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 - { - Public Partial classForm1:form the { - - - + PublicForm1 () - { + InitializeComponent (); A } at - Private voidForm1_Load (Objectsender, EventArgs e) - { -Loaddeskinfobydelflag (0); - - } in - Private voidLoaddeskinfobydelflag (intp) to { + //New Collection -list<deskinfo> list =NewList<deskinfo>(); the //Database String * stringstr ="Data Source=.;i Nitial catalog=mysql;integrated security=true"; $ //SQL statement, table with flag 0Panax Notoginseng stringsql ="Select Deskid,deskname,desknamepinyin,desknum from deskinfo where Deskdelflag ="+p; - //String sql = "SELECT * from Deskinfo"; theSqlConnection con =NewSqlConnection (str); + con. Open (); ASqlCommand cmd =NewSqlCommand (sql, con); the //cmd.reader for Query +SqlDataReader reader =cmd. ExecuteReader (); - //determine if a line is read $ if(reader. HasRows) $ { - //when I read it, - while(reader. Read ()) the { - //instantiate a table class, assign a value to each property, value as a value in the database, make a type conversionWuyiDeskinfo DK =Newdeskinfo (); theDk. Deskid = Convert.ToInt32 (reader["Deskid"]); -Dk. Deskname = reader["Deskname"]. ToString (); WuDk. Desknamepinyin = reader["Desknamepinyin"]. ToString (); -Dk. Desknum = reader["Desknum"]. ToString (); About //Add attributes to list $ list. ADD (DK); - } - - } A //Disable automatic column generation, no delflag column. +DGV. AutoGenerateColumns =false; the //binding Data -DGV. DataSource =list; $ the //Close Database Items the con. Dispose (); the cmd. Dispose (); the Reader. Dispose (); - } in } the}
Restaurant Item Enquiry