public Form1() { SqlCommand sqlCommand; SqlConnection sqlConnection;
string cn = "Server=ELVIS-PC;Initial Catalog=学生管理数据库; User ID=sa; Password=12345"; sqlConnection=new SqlConnection(cn); string sql= "select * from 学生表 "; sqlCommand=new SqlCommand(sql,sqlConnection); sqlConnection.Open();
DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(sql, sqlConnection); SqlCommandBuilder cb = new SqlCommandBuilder(da); da.Fill(ds); try {
// ListViewItem[] l = new ListViewItem[ds.Tables[0].Rows.Count];
ListViewItem l = null;
foreach (DataRow row in ds.Tables[0].Rows) {
l = new ListViewItem(row["学号"].ToString()); l.SubItems.Add(row["姓名"].ToString());