1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten usingSystem.Data.SqlClient; One A - namespaceRestaurant Review - { the Public Partial classForm1:form - { - PublicForm1 () - { + InitializeComponent (); - } + A Private voidForm1_Load (Objectsender, EventArgs e) at { -Loaddeskinfobydelid (0); - - } - stringstr ="Data Source=.;i Nitial catalog=mysql;integrated security=true"; - Private voidLoaddeskinfobydelid (intp) in { - //Enquiry tolist<deskinfo> list =NewList<deskinfo>(); + - stringsql ="SELECT * from deskinfo where Deskdelflag ="+p; theSqlConnection con =NewSqlConnection (str); * con. Open (); $SqlCommand cmd =NewSqlCommand (sql, con);Panax NotoginsengSqlDataReader reader =cmd. ExecuteReader (); - if(reader. HasRows) the { + while(reader. Read ()) A { theList. ADD (NewDeskinfo () + { -Deskid = Convert.ToInt32 (reader["Deskid"]), $Deskname = reader["Deskname"]. ToString (), $Desknamepinyin = reader["Desknamepinyin"]. ToString (), -Desknum = reader["Desknum"]. ToString () - }); the } - }WuyiDGV. DataSource =list; theDGV. rows[0]. Selected =false; -DGV. AutoGenerateColumns =false; Wu - con. Dispose (); About cmd. Dispose (); $ Reader. Dispose (); - } - - Private voidBtnok_click (Objectsender, EventArgs e) A { + //Add the stringsql =string. Format ("INSERT INTO Deskinfo (deskname,desknamepinyin,deskdelflag,desknum) VALUES (' {0} ', ' {1} ', 0, ' {2} ')", txtname.text,txtpinyin.text,txtnum.text); -SqlConnection con =NewSqlConnection (str); $ con. Open (); theSqlCommand cmd =NewSqlCommand (Sql,con); the cmd. ExecuteNonQuery (); theLoaddeskinfobydelid (0); the con. Dispose (); - cmd. Dispose (); in } the the Private voidBtndel_click (Objectsender, EventArgs e) About { the //Delete the intDelid = Convert.ToInt32 (DGV. selectedrows[0]. cells[0]. Value); the stringsql ="Update Deskinfo Set deskdelflag = 1 where deskid ="+Delid; +SqlConnection con =NewSqlConnection (str); - con. Open (); theSqlCommand cmd =NewSqlCommand (Sql,con);Bayi cmd. ExecuteNonQuery (); theLoaddeskinfobydelid (0); the - - the con. Dispose (); the cmd. Dispose (); the } the - the the } the}
Table Item Delete Table