我的窗体中就一个listBox和一个button,button代码如下:
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(LOCAL);uid=sa;pwd=;database=db_11";
conn.Open();
SqlCommand cmd = new SqlCommand("select * from tb_01", conn);
SqlDataReader sdr = cmd.ExecuteReader();
listBox1.Items.Clear();
while (sdr.Read())
{
listBox1.Items.Add(sdr[1].ToString());
}
程序编译运行无任何错误。
我在SQL2000数据库中新建数据库 db_11,然后新建表 tb_01,表中有5个列名,全都是int类型。可结果我按button,listBox中什么都没有显示,debug在while (sdr.Read())这步直接跳过listBox1.Items.Add(sdr[1].ToString());
不知道哪出了问题,请指教
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(LOCAL);uid=sa;pwd=;database=db_11";
conn.Open();
SqlCommand cmd = new SqlCommand("select * from tb_01", conn);
SqlDataReader sdr = cmd.ExecuteReader();
listBox1.Items.Clear();
while (sdr.Read())
{
listBox1.Items.Add(sdr[1].ToString());
}
程序编译运行无任何错误。
我在SQL2000数据库中新建数据库 db_11,然后新建表 tb_01,表中有5个列名,全都是int类型。可结果我按button,listBox中什么都没有显示,debug在while (sdr.Read())这步直接跳过listBox1.Items.Add(sdr[1].ToString());
不知道哪出了问题,请指教
2.sdr.read()第一条可能是空 要从下一条开始读
数据库中: 名称、数据类型、大小、默认值我都填了,共5列。
现在结果是按了button后listBox中只多了一行空值,等于啥都没有。
我是新人,也可能犯低级错误。