今天帮助别人调试程序时碰到了一个问题,他程序中用了如下的查询:
“select userid from login where userid='”+this.txtBox1.text.trim()+"'"
他数据库里的userid是字符类型,从文本框里读取的就是要查找的这个userid,在查询完成后用sqldatareader无法读出查询结果,有谁知道为什么,怎么解决这个问题?

解决方案 »

  1.   

    调试下  不就知道了
    我觉得最好 把string _strId=this.txtBox1.text.trim()+"
     "select userid from login where userid="+_strId
      

  2.   

    在调试的时候,先把sql语句放在查询分析器中执行一下,看是否有结果!
    另外你语句中的双引号是不是有问题啊,还有+前后是否要跟空格!
    “select userid from login where userid='”+this.txtBox1.text.trim()+"'"