//用于函数参数的个数不对 在查询表达式 '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");

解决方案 »

  1.   


    //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");
      

  2.   

    还是提示用于函数参数的个数不对 在查询表达式 'isnull(max([id]),0)' 中。
      

  3.   

    --用于函数参数的个数不对 在查询表达式 'isnull(max(xx.[id]),0)' 中
    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 "
      

  4.   


    --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
      

  5.   

    调试一下Sql是什么值吧?
    debug.write(sql.ToString())
      

  6.   

    select  top  20  * from M_product a  
    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的值吧。
      

  7.   

    1、加断点跟踪调试一下
    2、看看sql的值是什么
    3、然后把sql的值放到sql server很容易看出问题
      

  8.   

    在access中就有错,在sql2000中没错
      

  9.   

    这个分页有些麻烦,可以先计算页的数目,只要记录肯定是存在的,直接选就行了,不必再进行是否为空的判断了,把这个函数去掉,在Access中就可以用了。