关于SqlDataReader Read()方法的问题.
我用SqlDataReader读取数据然后分别把值赋给idtxt,nametxt,agetxt,classtxt运行下面这段代码在rdr = cmd.ExecuteReader();这里报错.错误为:
未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。
其他信息: 系统错误。
下面是我写的代码,请各位高手帮帮我解决一下,十分感谢!
-----------------------------------------------------------------------------------------------------------
private SqlConnection con =new SqlConnection();
private SqlCommand cmd = new SqlCommand();
private SqlDataReader rdr = null;
con.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["strConn"];
cmd.Connection = con;
private void selectbut_Click(object sender, System.EventArgs e)
{
cmd.CommandText = "ELECT id FROM student WHERE (id = "+selectTxt.Text+")";
con.Open();
rdr = cmd.ExecuteReader();
while(rdr.Read())
{
idtxt.Text = (string)rdr["id"];
nametxt.Text = (string)rdr["name"];
agetxt.Text = (string)rdr["age"];
classtxt.Text = (string)rdr["class"];
}
}
---------------------------------------------------
解决了,谢谢大家了!!!
[此贴子已经被作者于2006-11-28 22:30:12编辑过]