分页存贮过程参数"@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
该参数类型:不管设置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
解决方案 »
- asp.net里向access添加记录,数据库被锁?
- 取DataGrid绑定数据问题
- FormView中的DropDownList的SelectValue='<%#Bind("DeptInfo.DeptID")%>'为什么报错?
- ConnectionString 属性尚未初始化(我是新手,希望能得到各位的指点)
- 以前问过的一个问题,但需求一变,我就傻眼了~
- 常用SQL:高级应用
- 有没有将ASP。NET转换为ASP的软件吗?急啊!
- 求大神解说解说!不明白为什么数据库只有一条数据时就可以执行,但当数据库有两条数据时就出错了
- 关于mobile的样式表问题!《----高手帮忙啊(思归...)
- 一个简单的问题
- 问个基础问题:),在线等答案
- 求C#或vb。net整站源码,简单的新闻发布系统,供学习用,最好有详细文档 谢谢了!
事件跟踪是传入
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没有该条记录,奇怪
赞同跟踪condition
---------------------------
苦海无边 回头无岸
---------------------------
怎么跟踪@SQL?
好象事件跟踪器看不到
encoding="GB2312" 试试看