【问题标题】:An expression of non-boolean type specified in a context where a condition is expected, near 'no'在预期条件的上下文中指定的非布尔类型的表达式,靠近“否”
【发布时间】:2015-08-05 11:29:20
【问题描述】:
    private void button1_Click(object sender, EventArgs e)
    {
        cn.Open();
        st = "Select * from Info where Roll_no=" + textBox1.Text;
        cmd = new SqlCommand(st,cn);
        dr = cmd.ExecuteReader();
        if(dr.Read() == true)
        {
            textBox2.Text = dr.GetString(1);
            textBox3.Text = dr.GetString(2).ToString();
            textBox4.Text = dr.GetString(3).ToString();
            textBox5.Text = dr.GetString(4).ToString();
            textBox6.Text = dr.GetString(5);

            textBox1.Focus();
            button3.Enabled = true;
            button4.Enabled = true;
        }
        else
        {
            MessageBox.Show("No Such record exists");
            textBox1.Clear();
            textBox1.Focus();
            button3.Enabled = false;
            button4.Enabled = false;
        }
        dr.Close();
        cn.Close();
    }

【问题讨论】:

  • 什么是textBox1.TextRoll_no 的类型是什么?顺便说一句,如果George Boole 看到您的dr.Read() == true 部分,他可能会非常沮丧。只需if(dr.Read()) 就足够了。
  • roll_no 的类型是 int
  • @SonerGönül 希望我能给你一个 +1 的 George Boole 参考资料。
  • 为什么会出现这个错误

标签: c# ado


【解决方案1】:

键入您的查询,例如:“Select * from Info where Roll_no = '”+ textBox1.Text+'" ;"; 希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 2011-09-22
    • 2013-02-11
    • 1970-01-01
    相关资源
    最近更新 更多