
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();
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步