asp.net 在用ExecuteScalar()的时候出现[ '=' 附近有语法错误。]提示!

..stringSql;Sql="select*fromtb_bookinfoorderbyinTimedesc";OleDbConnectionConn=newOleD... ..
string Sql;
Sql = "select * from tb_bookinfo order by inTime desc";
OleDbConnection Conn = new OleDbConnection();
Conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringto"];
Conn.Open();
OleDbDataAdapter Ad = new OleDbDataAdapter(Sql, Conn);
DataSet ds = new DataSet();
Ad.Fill(ds);
test = "<table>";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
test += "<tr><td>" + ds.Tables[0].Rows[i]["type"].ToString() + "</td><td>" + ds.Tables[0].Rows[i]["bookcode"].ToString() + "</td><td>" + ds.Tables[0].Rows[i]["bookname"].ToString() + "</td><td>" + ds.Tables[0].Rows[i]["pubname"].ToString() + "</td><td>" + ds.Tables[0].Rows[i]["translator"].ToString() + "</td><td>" + ds.Tables[0].Rows[i]["bcase"].ToString() + "</td><td>" + ds.Tables[0].Rows[i]["author"].ToString() + "</td><td>" + GetType(ds.Tables[0].Rows[i]["bookcode"].ToString()) + "</td><td>" + ds.Tables[0].Rows[i]["oper"].ToString() + "</td></tr>";
}
test += "</table>";
}
public static string GetType(string Value) //前台得到类别
{
if (Value != "")
{
string Sql, Sqlcount, Text1, Text2, Sqlcount1, Sqlcount2, Sort;
Sql = "select [name] from tb_readertype";
OleDbConnection Conn = new OleDbConnection();
Conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionStringto"];
Conn.Open();
OleDbDataAdapter Ad = new OleDbDataAdapter(Sql, Conn);
DataSet ds = new DataSet();
Ad.Fill(ds);
Value = "<table><tr>";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Sqlcount1 = "SELECT COUNT(*) AS Expr1 FROM tb_readertype INNER JOIN tb_reader ON tb_readertype.name = tb_reader.type INNER JOIN tb_borrowandback ON tb_reader.id = tb_borrowandback.readerid (tb_borrowandback.isback = 0) AND (tb_readertype.name = @Name) AND (tb_borrowandback.bookcode = @tuid)";
OleDbCommand Cmd1 = new OleDbCommand();
Cmd1.Connection = Conn;
Cmd1.CommandText = Sqlcount1;
Cmd1.Parameters.Add("@Name", SqlDbType.VarChar);
Cmd1.Parameters["@Name"].Value = ds.Tables[0].Rows[i]["name"].ToString();
Cmd1.Parameters.Add("@tuid", SqlDbType.VarChar);
Cmd1.Parameters["@tuid"].Value = Value.ToString();
Text1 = Convert.ToString(Cmd1.ExecuteScalar());
Cmd1.Dispose();
Cmd1 = null;
Sqlcount2 = "SELECT COUNT(*) AS Expr1 FROM tb_readertype INNER JOIN tb_reader ON tb_readertype.name = tb_reader.type INNER JOIN tb_borrowandback ON tb_reader.id = tb_borrowandback.readerid (tb_borrowandback.isback = -1) AND (tb_readertype.name = '" + ds.Tables[0].Rows[i]["name"].ToString() + "') AND (tb_borrowandback.bookcode = '" + Value.ToString() + "')";
OleDbCommand Cmd2 = new OleDbCommand();
Cmd2.Connection = Conn;
Cmd2.CommandText = Sqlcount2;
Text2 = Convert.ToString(Cmd2.ExecuteScalar());
Cmd2.Dispose();
Cmd2 = null;
Value += "<td>" + Text1.ToString() + "</td><td>" + Text2.ToString() + "</td>";
}
Value += "</tr></table>";
}
return Value;
}
}
展开
 我来答
ludonggreat
2012-01-15 · 超过10用户采纳过TA的回答
知道答主
回答量:52
采纳率:0%
帮助的人:24万
展开全部
少了where 一般你可以打个断点 把sql语句拷出来看看,直接放到sqlserver里测试下 错误很快就看出来了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
翼帆
2012-01-15 · TA获得超过1729个赞
知道小有建树答主
回答量:819
采纳率:60%
帮助的人:518万
展开全部
Sqlcount1 ,Sqlcount2 缺少where
tb_borrowandback.readerid 后面加上where就可以了。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式