6. ListView (2)

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_2015_1_25{ Public Partial classFormsql:form { PublicFormsql () {InitializeComponent (); }        Private voidButton1_Click (Objectsender, EventArgs e) {            //First Kindstring sqls = "server=.;            database= operation; user=sa;pwd=123 "; SqlConnection conn = new SqlConnection (SQLS);//Database Connection ClassesSqlCommand cmd = conn. CreateCommand ();//Database Access Classescmd.commandtext = "Select *from student";//writing T-SQL statementsConn. Open ();//Open ConnectionSqlDataReader dr = cmd. ExecuteReader ();//perform access to return dataWhile (Dr. Read ())//reads a row of data through the read down pointer{            ListViewItem lt = new ListViewItem (); Lt. Text = dr["Sno"].            ToString (); Lt. SubItems.Add (dr["sname").            ToString ()); Lt. SubItems.Add (dr["Ssex").            ToString ()); Lt. SubItems.Add (dr["class").            ToString ()); ListView1.Items.Add (LT); }            Conn. Close ();//Close Connection//The second Kind            stringA ="server=.; database= work; user=sa;pwd=123"; SqlConnection b=NewSqlConnection (a); SqlCommand C=B.createcommand (); C.commandtext="Select*from Teacher";            B.open (); SqlDataReader D=C.executereader ();  while(D.read ()) {ListViewItem F=NewListViewItem (); F.text= d["TNO"].                ToString (); F.subitems.add (d["Tname"].                ToString ()); F.subitems.add (d["Tsex"].                ToString ()); F.subitems.add (d["Tbirthday"].                ToString ()); F.subitems.add (d["Prof"].                ToString ()); F.subitems.add (d["Depart"].                ToString ());            LISTVIEW1.ITEMS.ADD (f);        } b.close (); }    }}         

6. ListView (2)

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.