asp.net用数据库进行信息查询,为什么会出现列名无效?以下代码中第一个if可以执行为什么第二个if就不行了
?“姓名”“学号”都在一个表里,代码也没差,为什如果用“姓名”查询就会“列名无效”?请教各位,谢谢……
if (this.RadioButton1.Checked == true)
{
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select*from chlesson where 学号=" + this.TextBox1.Text + "", con);
sda.Fill(ds, "chlesson");
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
if (this.RadioButton2.Checked == true)
{
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select*from chlesson where 姓名=" + this.TextBox2.Text + "", con);
sda.Fill(ds, "chlesson");
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
答案:类型不对吧 姓名='"+ this.TextBox2.Text + "'
外面要加一对单引号
上一个:怎么运行ASP动态网页?
下一个:asp语言中如何调用产品相对应的类别名称?