(LINQ) (5) Examples of the LINQ Tutorial: query by adding, deleting, modifying, and deleting a single table operation

Source: Internet
Author: User
Add operation Private Void Toolstripbtnadd_click ( Object Sender, eventargs E)
{
// Create a new class and assign values to the attributes
Student mystudent = New Student ();
Mystudent. studentname = " Meetweb " ;
Mystudent. Sex = " Man " ;
Mystudent. Old = 17 ;
Dataclasses1datacontext DB = New Dataclasses1datacontext (sqlconstr );
DB. Student. insertonsubmit (mystudent );
DB. submitchanges ();
Dataload ();
// This. Maid ();
}

Delete operation

Private Void Toolstripbtndel_click ( Object Sender, eventargs E)
{
// Delete action
Dataclasses1datacontext DB = New Dataclasses1datacontext (sqlconstr );
// Need to delete the ID is 6
Student mystudent = dB. gettable <student> (). First <student> (P => P. ID = 4 );
DB. Student. deleteonsubmit (mystudent );
}

Update operation

Private Void Toolstripbtnsave_click ( Object Sender, eventargs E)
{
// Modify action
Dataclasses1datacontext DB = New Dataclasses1datacontext (sqlconstr );
// Need to update the ID is 6
Student mystudent = dB. gettable <student> (). First <student> (P => P. ID = 5 );
Mystudent. Old = 18 ;
Mystudent. Sex = " Woman " ;
DB. submitchanges ();
}

Multi-condition Query

Private List <student> Search ( String ID, String Studentname)
{
Dataclasses1datacontext DB = New Dataclasses1datacontext (sqlconstr );
List <student> mystudent = dB. gettable <student> (). First <student> (P => P. ID = 4 & P. studentname = studentname). tolist ();

Return mystudent;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.