c# SQL语句错误!急,在线等!提示,附近有语法错误。

来源:百度知道 编辑:UC知道 时间:2024/09/25 03:23:20
string sql = string.Format("select count(*) from u where uno={0} , password={1}", this.cboId.Text.Trim(), this.txtKey.Text.Trim());
,改为and,提示列名sa无效。加上group by也不对提示列名sa无效。

正解在这里:
我想楼主的数据库uno,password这两列应该是字符串类型的吧。

string sql = string.Format("select count(*) from u where uno='{0}' and password='{1}'", this.cboId.Text.Trim(), this.txtKey.Text.Trim());

说错了。。。

把大括号去掉

string sql = string.Format("select count(*) from u where uno={0} and password={1}", this.cboId.Text.Trim(), this.txtKey.Text.Trim());

把逗号改为and就Ok了

列名无效有可能是你的数据库表中没有这个字段

要使用group by必须在select后面选择的字段中包含分组的字段

你试试这个:
string sql="select * from u where uno='"+this.cbold.Text.Trim()+"' ,password='"+this.txtKey.Text.Trim()+"'";

三楼正解, 怎么where条件有逗号的,呵呵 不是AND 就是 OR