字符串 '' 后的引号不完整

[复制链接]
查看11 | 回复3 | 2019-4-22 12:31:55 | 显示全部楼层 |阅读模式
s = "select count(*) fromSelectResult where StudentID=" + (string)(Session["ID"]) + "'";

SqlCommand co = new SqlCommand(s, Conn);

da.Fill(ds);

int count = 0;

count = (int)co.ExecuteScalar();

if (count != 0)

{

Conn.Close();

Response.Write("");

return;

}
总是提示 count = (int)co.ExecuteScalar();
字符串 '' 后的引号不完整为什么啊

回复

使用道具 举报

千问 | 2019-4-22 12:31:55 | 显示全部楼层
你这个错误是编译器报的错误还是运行时错误?我测试了,可以编译通过,运行时组织成的sql语句语法也正确,会不会是因为bt、nr、sj变量中的内容含有单/双引号或者单括号呢?也可以把单括号和汉字之间添加空格试一试。
回复

使用道具 举报

千问 | 2019-4-22 12:31:55 | 显示全部楼层
s = "select count(*) fromSelectResult where StudentID=" + (string)(Session["ID"]);如果是数字就这样s = "select count(*) fromSelectResult where StudentID=‘" + (string)(Session["ID"])
回复

使用道具 举报

千问 | 2019-4-22 12:31:55 | 显示全部楼层
字符串应该用""不是单引号
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行