//用于函数参数的个数不对 在查询表达式 'isnull(max(xx.id),0)' 中。
StringBuilder sql = new StringBuilder("select top "+PageSize+" * from M_product a ");
sql.Append(" where a.[id]>( select isnull(max(xx.[id]),0) from ( select TOP " + PageSize2 + " [id] from M_product where 1=1 ");
if (type != null)
{
sql.Append(" and [type]=" + type.Replace("'", "") );
}
if (product_type != null)
{
sql.Append(" and product_type=" + product_type.Replace("'", ""));
}
sql.Append(" ORDER BY [id] desc)xx ) ");
if (type != null)
{
sql.Append(" and a.[type]=" + type.Replace("'", "") );
}
if (product_type != null)
{
sql.Append(" and a.product_type=" + product_type.Replace("'", ""));
} sql.Append(" ORDER BY a.[id] desc");
// SELECT 子句中包含一个保留字、拼写错误或丢失的参数,或标点符号不正确。 StringBuilder sql = new StringBuilder("select top "+PageSize+" * from M_product a ");
sql.Append(" where a.[id]>( select max(xx.[id]) from ( select TOP " + PageSize2 + " [id] from M_product where 1=1 ");
if (type != null)
{
sql.Append(" and [type]=" + type.Replace("'", "") );
}
if (product_type != null)
{
sql.Append(" and product_type=" + product_type.Replace("'", ""));
}
sql.Append(" ORDER BY [id] desc)xx ) ");
if (type != null)
{
sql.Append(" and a.[type]=" + type.Replace("'", "") );
}
if (product_type != null)
{
sql.Append(" and a.product_type=" + product_type.Replace("'", ""));
} sql.Append(" ORDER BY a.[id] desc");
//try:
StringBuilder sql = new StringBuilder("select top "+PageSize+" * from M_product a ");
sql.Append(" where a.[id]>( select isnull(max([id]),0) from ( select TOP " + PageSize2 + " [id] from M_product where 1=1 ");
if (type != null)
{
sql.Append(" and [type]=" + type.Replace("'", "") );
}
if (product_type != null)
{
sql.Append(" and product_type=" + product_type.Replace("'", ""));
}
sql.Append(" ORDER BY [id] desc)xx ) ");
if (type != null)
{
sql.Append(" and a.[type]=" + type.Replace("'", "") );
}
if (product_type != null)
{
sql.Append(" and a.product_type=" + product_type.Replace("'", ""));
} sql.Append(" ORDER BY a.[id] desc");
string sql="select top 20 * from M_product a where "
sql+="a.[id]>( select isnull(max(xx.[id]),0) "
sql+="from ( select TOP 0 [id] from M_product where 1=1 "
sql+="and [type]=1 and product_type=1 ORDER BY [id] desc)xx ) " sql+="and a.[type]=1 and a.product_type=1 ORDER BY a.[id] desc "
--SELECT 子句中包含一个保留字、拼写错误或丢失的参数,或标点符号不正确。 commandText "select top 20 * from M_product a where a.[id]>( select max(xx.[id]) from ( select TOP 0 [id] from M_product where 1=1 and [type]=1 and product_type=1 ORDER BY [id] desc)xx ) and a.[type]=1 and a.product_type=1 ORDER BY a.[id] desc" string
debug.write(sql.ToString())
where a.[id]>
( select isnull(max(xx.[id]),0) from
( select TOP 10 [id] from M_product where 1=1 and [type]=1 and
product_type=1 ORDER BY [id] desc ) xx
)
and a.[type]=1 and a.product_type=1 ORDER BY a.[id] desc数据分页吧。
这个语句没发现有什么错误,可能是你连接字符串的时候有些问题吧,先看一下SQL的值吧。
2、看看sql的值是什么
3、然后把sql的值放到sql server很容易看出问题