aa = "select * from ceshi where " + this.DropDownList1.SelectedValue + "='" + this.TextBox1.Text.Trim() +"'";
aa = "select * from ceshi where '" + this.DropDownList1.SelectedValue + "'='" +this.TextBox1.Text.Trim() +"'";
aa = "select * from ceshi where '" + this.DropDownList1.SelectedValue + "'=''"+this.TextBox1.Text.Trim() +"''";
第一条是对的,但文本变量this.DropDownList1.SelectedValue好像要用''引起来才行,如第二句,为什么可以不引起来;但第二句查询不到,因为我的this.TextBox1.Text.Trim()只输入数字,好像也要用''引起来才行(不知对不对,但"select * from ceshi where  id='1'"是行的),如第三句;但第三句执行是错的,语法错误 (操作符丢失) 在查询表达式 ''id'=''1''' 中,这是什么问题?请高手帮忙!!

解决方案 »

  1.   

    看看aa   具体的值
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
      

  2.   

    第一句应该是对的,如果你输入的是数字而且数据库里面的这一字段也是数字类型,那么就不要用‘引起来,如下:
    aa   =   "select   *   from   ceshi   where   "   +   this.DropDownList1.SelectedValue   +   "="   +   this.TextBox1.Text.Trim()   +"; 
      

  3.   

    你把后面的符号都去掉不可以吗?
    ============
    因为我的this.TextBox1.Text.Trim()只输入数字,好像也要用''引起来才行=====================
    即使你输入的是数字,但是你没有类型转换呀,所以还是字符串啦。
      

  4.   

    在查询表达式   ''id'=''1'''   中
    应当是 "id=1" ,跟踪调试一下,稍稍改改即可
      

  5.   


    aa = "select * from ceshi where [" + this.DropDownList1.SelectedValue + "]='" +   this.TextBox1.Text.Trim() + "'"; 
    aa = "select * from ceshi where [" + this.DropDownList1.SelectedValue + "]='" +
    this.TextBox1.Text.Trim() +"'"; 
    aa = "select * from ceshi where [" + this.DropDownList1.SelectedValue + "]='" +
    this.TextBox1.Text.Trim() +"'"; 
    如果DropDownList1.SelectedValue是列名称的话,则上面代码不会出错,你可以试试