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;
}
} 展开
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;
}
} 展开
展开全部
少了where 一般你可以打个断点 把sql语句拷出来看看,直接放到sqlserver里测试下 错误很快就看出来了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询