我的这段代码,如果
private void InitPage()
{
string ImgID = Request.QueryString["ImgID"].ToString();
SqlConnection con = DB.CreateDB();
con.Open();
SqlCommand cmd = new SqlCommand("select * from ImgNews2 where ImgID='"+ImgID+"'", con);
//如果我在这里注释掉string ImgID = Request.QueryString["ImgID"].ToString();然后把变量ImgID随便赋个3都能正常.
SqlDataReader sdr = cmd.ExecuteReader(); //就是这里报错,说是用户代码未处理,SQL异常.
while (sdr.Read())
{
this.Label1.Text = sdr.GetString(2);
this.Image1.ImageUrl = sdr.GetString(1);
this.Label2.Text = sdr.GetString(3);
}
sdr.Close();
con.Close();
}
就是我传值后发生上述错误.请大家指点一下.谢谢大家