650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/193333I17-0.gif "alt =" y_0034.gif "/> after WinForm is connected to the database, the data in the form can be added to the database, the data in the database can be displayed in the Windows window. However, the buttons on the form have to be changed this time, And ListView is used this time.
Let's take a look at the specific code and running results.
Private void Form1_Load (object sender, EventArgs e) {FillListView () ;}/// <summary> /// fill the table view /// </summary> private void FillListView () {string SQL = "select * from Friends"; string connString = @ "server = (local); database = SchoolDB; uid = sa; pwd = 514420 ;"; sqlConnection connection = new SqlConnection (connString); SqlCommand command = connection. createCommand (); connection. open (); command. commandText = SQL; // data table dt able dt = new DataTable (); // SQL data configurator SqlDataAdapter sda = new SqlDataAdapter (command ); // There is a Fill method in the configurator to Fill sda. fill (dt); // use the method of looping to Fill each row of data rows.) foreach (DataRow row in dt. rows) {// Add all fields in the database to the window int id = (int) row ["id"]; string name = (string) row ["name"]; bool sex = (bool) row ["sex"]; DateTime birthday = (DateTime) row ["birthday"]; decimal salary = (decimal) row ["salary"]; // Add the content value of each row to the window ListViewItem lvi = new ListViewItem (); lvi. text = id. toString (); lvi. subItems. add (name); lvi. subItems. add (sex. toString (); lvi. subItems. add (birthday. toString (); lvi. subItems. add (salary. toString (); this. lview. items. add (lvi);} connection. close ();}
Running result:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1933332M9-1.png "title =" Capture. PNG "alt =" 121953764.png"/>
The most important thing is to add the column names in the database to the window, and then add the values one by one. When will this happen...
At the very beginning, this level has been achieved, and the progress has been improved slowly!
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1933335Y8-2.gif "alt =" j_0047.gif "/> Ajax Girl, come on! 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1933335Y8-2.gif "alt =" j_0047.gif "/>
This article is from the "Ajax girl" blog!