T_Sql查询语句
string sql = "select top @Top Id, PublishHouse from T_Publishers";
SqlParameter para = new SqlParameter("@Top", Top);
-> 运行时,报错:@Top附近有语法错误
-> 原因:@Top是查询条件,不是表中的列
-> 解决方法:把@Top换成字符串拼接方式
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append(" Id, PublishHouse");
strSql.Append(" from T_Publishers");
更多交流;q619267707
原文地址:https://www.cnblogs.com/kengzhu/p/9002313.html
时间: 2024-10-23 12:48:02