怎么下不了啊
请各位帮我看看这段代码:到con.Open();就
出现了这样的异常:
处理的“System.NullReferenceException”类型的异常出现在 system.data.dll 中。
其他信息: 未将对象引用设置到对象的实例
private void button2_Click(object sender, System.EventArgs e)
{
foreach(char ch in this.textBox2.Text.ToCharArray())
{
if(!char.IsDigit(ch))
return;
}
SqlConnection con = new SqlConnection("server=.; database=Test;uid=sa;pwd=sa");
con.Open();
string sql ="select * from imgTest where imgID ="+this.textBox2.Text.Trim();
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataReader sdr = cmd.ExecuteReader();
byte[]imgs = null;
while(sdr.Read())
{
imgs =(byte[])sdr.GetValue(1); }
sdr.Close();
con.Close();
Stream stm = new MemoryStream(imgs,0,imgs.Length);
}
this.pictureBox1.Image = System.Drawing.Image.FromStream(stm);
}
这是什么原因??????????????