代码
SqlConnection conn = BaseClass.DBConn.CjCon();//创建一个SQL SERVER连接对象。
try
{
conn.Open();
SqlDataAdapter sda
= new SqlDataAdapter("select xh as 学号,xm from xsb", conn);
DataSet ds
= new DataSet();
sda.Fill(ds);

this.listView1.Columns.Add("xh", 80, HorizontalAlignment.Center);
this.listView1.Columns.Add("姓名", 60, HorizontalAlignment.Center);//增加列标题
listView1.View = View.Details;
listView1.GridLines
= true;//显示网格线。。
string[] str = new string[2];
foreach (DataRow row in ds.Tables[0].Rows)
{
str[
0] = row["学号"].ToString();
str[
1] = row["xm"].ToString();
ListViewItem item
= new ListViewItem(str, 0);
listView1.Items.Add(item);
}
}
catch (Exception er)
{
MessageBox.Show(er.ToString());
conn.Close();
}

 

相关文章:

  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2021-06-27
  • 2021-08-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2022-02-28
  • 2021-10-29
  • 2022-01-04
  • 2022-12-23
相关资源
相似解决方案