T_Sql query statement
string sql = "select top @Top Id, PublishHouse from T_Publishers";
SqlParameter para = new SqlParameter("@Top", Top);
-> At runtime, an error is reported: Syntax error near @Top
-> Reason: @Top is a query condition, not a column in the table
-> Solution: replace @Top with string concatenation
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append(" Id, PublishHouse");
strSql.Append(" from T_Publishers");
More exchanges; q619267707