Use the LINQ method to change the search and delete

Source: Internet
Author: User

  func<string, string> fc = Delegate (string a)//{//A + = "Hello";            return A;            //}; MessageBox.Show (FC ("5").            ToString ());            Dataclasses1datacontext context = new Dataclasses1datacontext (); list<bread> list = Context.bread.Where (r = Convert.todecimal (R.breadprice.tostring ()) < 15).            ToList ();            var list2 = from quary in Context.bread where Convert.todecimal (quary.breadprice.ToString ()) < select Quary;            Datagridview1.autogeneratecolumns = true; Datagridview1.datasource = list2;/////////////////////////////////////////////////////////////////////////////// public class Studentda {private Dataclasses1datacontext _context        ;        Public Studentda () {_context = new dataclasses1datacontext (); }//Add data public void Insert (Student data) {_context.            Student.insertonsubmit (data); _context.        SubmitChanges (); }//Modify data public void update (Student data) {Student sdata =_context. Student.single (r = R.sno = = data.            Sno); if (sdata! = null) {sdata. Sno = data.                Sno; Sdata. Sname = data.                Sname; Sdata. Ssex = data.                Ssex; Sdata. Sbirthday = data.                Sbirthday; _context.            SubmitChanges (); }}//delete data public void Delete (Student data) {Student sdata = _context. Student.single (R=>r.sno==data.            Sno); _context.            Student.deleteonsubmit (sdata); _context.        SubmitChanges (); ////////Delete public void Delete (String sno) {Student data = _context According to the student number.            Student.single (r = R.sno = = Sno); if (data! = NULL) {_context.                Student.deleteonsubmit (data); _context. SubmitchaNges (); }}///////////queries all student data public list<student> Select () {return _context. Student.tolist (). Count>0? _context.        Student.tolist (): null; }///////////////Queries public Student Select (String sno) {return _context according to the student number. Student.where (r = R.sno = = Sno).        First (); }/////////////Query Public list<student> selectbyname (string sname) {List <student&gt by student name ; List= _context. Student.where (r = r.sname.contains (Sname)).           ToList (); Return list. Count>0?        List:null; }    }}////////////////////////////////////////////////////////////////////////////////////////////////////////////               Add data to the database Student the new Student {sno=textbox1.text, Sname=textbox2.text, Ssex=radiobutton1.checked? "                            Male ":" female ", Sbirthday=datetimepicker1.value, Class=textbox3.text,             };            New Studentda (). Insert (data),/////////////query data from database using LINQ method private void Form3_load (object sender, EventArgs e) {            list<student> list = new Studentda (). Select ();                if (list = null) {Datagridview1.autogeneratecolumns = true;            Datagridview1.datasource = list;            }//////////uses LINQ methods to query private void Button1_Click (object sender, EventArgs e) from the database by name {            list<student> list = new Studentda (). Selectbyname (TextBox1.Text);                if (list = null) {Datagridview1.autogeneratecolumns = true;            Datagridview1.datasource = list; }/////////Delete data from database using LINQ method private void Button2_Click (object sender, EventArgs e) {if            (DataGridView1.SelectedRows.Count > 0) {Student data = (Student) datagridview1.selectedrows[0].                Databounditem; NeW STUDENTDA (). Delete (data);            } Datagridview1.autogeneratecolumns = true;        Datagridview1.datasource = new Studentda (). Select (); private void Button3_Click (object sender, EventArgs e) {if (DataGridView1.SelectedRows.Count & Gt 0) {Form4 f = new FORM4 ((Student) datagridview1.selectedrows[0].                Databounditem);            F.show (); }} private Student sdata;////The selected information to the appropriate local constructor public Form4 (Student data) {initializecom            Ponent ();        sdata = data; The private void Form4_load (object sender, EventArgs e) {TextBox1.Text = Sdata.            Sno; TextBox2.Text = sdata.            Sname; TextBox3.Text = sdata.            Class; if (sdata.            Ssex = = "Male") {radiobutton1.checked = true;            } else {radiobutton2.checked = true; } DateTimePicker1.Value = DateTime.Parse (sdata.        Sbirthday.tostring ()); }////////////////////////////////////////////////////////////////////////The returned information is modified and returned to the database private void button1_            Click (object sender, EventArgs e) {Student sdata = new Student (); Sdata.            Sno = TextBox1.Text; Sdata.            Sname = TextBox2.Text; Sdata.            Class = TextBox3.Text; Sdata. Ssex = radiobutton1.checked?            "Male": "Female"; Sdata.            Sbirthday = Datetimepicker1.value;            New STUDENTDA (). Update (sdata); This.        Close (); }

Use the LINQ method to change the search and delete

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.