分页存贮过程参数"@Condition"不能传入中文字符,文本框this.txtName.Text.Trim()含有中文就搜索不了记录,字母和数字就可以,
该参数类型:不管设置System.Data.SqlDbType.NVarChar还是System.Data.SqlDbType.VarChar都不行
搞了一整天了,那位大哥帮帮小弟,感谢不尽
程序代码:
                           SqlConnection con=com.qlcon;
con.Open();
SqlCommand comm=new SqlCommand();
comm.CommandType=CommandType.StoredProcedure;
comm.CommandText="GetPagingData";
comm.Connection=con;
comm.Parameters.Add("@TBName",System.Data.SqlDbType.VarChar,2000).Value="web";
comm.Parameters.Add("@KeyField",System.Data.SqlDbType.VarChar,2000).Value="编号";
comm.Parameters.Add("@PageSize",System.Data.SqlDbType.Int).Value=this.pagesize;
comm.Parameters.Add("@CurPage",System.Data.SqlDbType.Int).Value=Convert.ToInt32(ViewState["pageindex"]);
comm.Parameters.Add("@KeyAscDesc",System.Data.SqlDbType.VarChar,4).Value="desc";
            comm.Parameters.Add("@Fields",System.Data.SqlDbType.VarChar,2000).Value="编号,名称,仓库编号,数量";
 comm.Parameters.Add("@Condition",System.Data.SqlDbType.NVarChar,2000).Value="仓库编号 like '%"+this.DDLType.SelectedValue.Trim()+"%' and 名称 like '%"+this.txtName.Text.Trim()+"%' and 数量>"+Convert.ToInt32(this.txtQty.Text.Trim());

 comm.Parameters.Add("@Order",System.Data.SqlDbType.VarChar,200).Value="";
SqlDataReader dr;
dr=comm.ExecuteReader();
dr.Read();
this.DataGrid1.DataSource=dr;
this.DataBind();
comm.Dispose();
con.Close();
分页存贮过程如下:
CREATE proc dbo.GetPagingData(
@TBName nvarchar(2000)='',--表名,视图,SQL
@KeyField nvarchar(100)='ID',--关键字段名,默认为 ID,该字段要求是表中的索引 或 无重复和不为空的字段
@PageSize int=10,--每页的记录数,默认为 10
@CurPage int=1,--表示当前页 1
@KeyAscDesc nvarchar(4)='ASC',--关键字的升、降序,默认为升序 ASC , 降序为 DESC
@Fields nvarchar(2000)='*',--所选择的列名,默认为全选
@Condition nvarchar(2000)='1=1',--where 条件,默认为空
@Order nvarchar(200)=''--排序条件,默认为空
)ASif @TBName = ''
begin
       raiserror('请指定表名!',11,1)
       return
end
ELSE
BEGIN
IF(PATINDEX('%from%',@TBName)>0)
BEGIN
SET @TBName = ' (' + @TBName + ') tempTable '
END
END
if @PageSize <=0 or @CurPage <0 
   begin
       raiserror('当前页数和每页的记录数都必须大于零!',11,1)
       return
   end
if @KeyAscDesc = 'DESC'
set @KeyAscDesc = '<'
else
set @KeyAscDesc = '>'
if @Condition <> ''
set @Condition = ' where ' + @Condition
declare @SQL nvarchar(2000)set @SQL = ''
if @CurPage = 1
   set @SQL = @SQL + 'SELECT Top ' + cast(@PageSize as nvarchar(20)) + ' ' + @Fields + ' FROM ' + @TBName + @Condition + ' ' + @Order
else
   begin
declare @iTopNum int
set @iTopNum = @PageSize * (@CurPage - 1)
set @SQL = @SQL + 'declare @sLastValue nvarchar(100)' + char(13)
set @SQL = @SQL + 'SELECT Top ' + cast(@iTopNum as nvarchar(20)) + ' @sLastValue=' + @KeyField + ' FROM ' + @TBName + @Condition + ' ' + @Order + char(13)declare @Condition2 nvarchar(200)
if @Condition = ''
   set @Condition2 = ' where ' + @KeyField + @KeyAscDesc + '@sLastValue '
else
   set @Condition2 = ' and ' + @KeyField + @KeyAscDesc + '@sLastValue '
set @SQL = @SQL + 'SELECT Top ' + cast(@PageSize as nvarchar(20)) + ' ' + @Fields + ' FROM ' + @TBName + @Condition + @Condition2 + @Order
   end
EXECUTE sp_executesql @SQL
GO

解决方案 »

  1.   

    你跟踪下Condition在存储过程里面是什么值,最好别在传入参数里面设定默认值。
      

  2.   

    chenxi6713(番茄)提醒,
    事件跟踪是传入
    exec GetPagingData @TBName = 'prdt', @KeyField = 'prd_no', @PageSize = 18, @CurPage = 1, @KeyAscDesc = 'desc', @Fields = 'prd_no,name,wh', @Condition = N'wh like ''%%'' and name like ''%14204金葱绳%''', @Order = ''也就是@Condition是等于N'wh like ''%%'' and name like ''%14204金葱绳%'''在查询分析器可以查到该记录,但是在网页datagrid没有该条记录,奇怪
      

  3.   

    这和存储过程里设定默认值是没关系的 
    赞同跟踪condition
      

  4.   

    继续跟踪 看看 最后得@SQL是什么东西
    ---------------------------
    苦海无边 回头无岸
    ---------------------------
      

  5.   

    robert2004(我能发财)
    怎么跟踪@SQL?
    好象事件跟踪器看不到
      

  6.   

    在web.config中改encoding为
    encoding="GB2312" 试试看