using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace NTIMS { public partial class Form1 : Form { SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=WelkinDB;Integrated Security=True"); SqlCommand cmd; DataTable dt; SqlDataAdapter da; private ListView listView1; private Button button1; DataSet ds; static void Main() { new Form1(); } public Form1() { InitializeComponent(); } private void InitializeComponent() { this.listView1 = new System.Windows.Forms.ListView(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // listView1 // this.listView1.HideSelection = false; this.listView1.Location = new System.Drawing.Point(13, 12); this.listView1.Name = "listView1"; this.listView1.Size = new System.Drawing.Size(508, 278); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.UseWaitCursor = true; // // button1 // this.button1.Location = new System.Drawing.Point(13, 303); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(112, 23); this.button1.TabIndex = 1; this.button1.Text = "Fill List"; this.button1.UseVisualStyleBackColor = true; this.button1.UseWaitCursor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.ClientSize = new System.Drawing.Size(533, 338); this.Controls.Add(this.button1); this.Controls.Add(this.listView1); this.Name = "Form1"; this.Load += new System.EventHandler(this.Form1_Load_1); this.ResumeLayout(false); private void button1_Click(object sender, EventArgs e) { listView1.Items.Clear(); this.listView1.Columns.Add("ID",10); this.listView1.Columns.Add("Surname", 70); con.Open(); cmd = new SqlCommand("Select * from student", con); da = new SqlDataAdapter(cmd); ds = new DataSet(); da.Fill(ds, "testTable"); con.Close(); dt = ds.Tables["testTable"]; int i; for (i=0;i<=dt.Rows.Count - 1;i++) { listView1.Items.Add(dt.Rows[i].ItemArray[0].ToString()); listView1.Items[i].SubItems.Add(dt.Rows[i].ItemArray[1].ToString()); } } private void Form1_Load(object sender, EventArgs e) { listView1.Columns.Add("ID", 20); listView1.Columns.Add("Chinese Name", 40); listView1.View = View.Details; } private void Form1_Load_1(object sender, EventArgs e) { } } }Ben