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 + "'
外面要加一对单引号
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

大家正在搜

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网