对象名 'dbo.forsafe' 无效。
输入用户名点击"搜索",就出现对象名 'dbo.forsafe' 无效。输入注册时间就不会
CS代码
程序代码:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using DataCommon; using Common; public partial class admin_UserInfoManager : System.Web.UI.Page { int pageindex = 1; int pagesize = PageFoot.PageSize; string sort = string.Empty; string searchkey = string.Empty; string starttime = string.Empty; string endtime = string.Empty; protected void Page_Load(object sender, EventArgs e) { int.TryParse(Request.QueryString["pageindex"], out pageindex); searchkey = PubCommon.GetQueryString("searchkey"); starttime = PubCommon.GetQueryStringTime("starttime"); endtime = PubCommon.GetQueryStringTime("endtime"); if (pageindex < 1) pageindex = 1; if (!Page.IsPostBack) { int docount = 0; Repeater1.DataSource = SqlHelper.GetListPage(pagesize, pageindex, ref docount, sort, searchkey, starttime, endtime, "UserInfo_select"); Repeater1.DataBind(); foot.InnerHtml = PageFoot.PageSatte(pagesize, pageindex, docount, PageFoot.GetPageUrl(), 1); } } protected void LinkButton1_Click(object sender, EventArgs e) { try { LinkButton lb = (LinkButton)sender; int id = 0; int.TryParse(, out id); int i = UserInfo.Delete(id); if (i > 0) { MBox.RefUrl(2); } else { Response.Redirect("../Error.aspx"); } } catch { Response.Redirect("../Error.aspx"); } } protected void btnSouSuo_Click(object sender, EventArgs e) { searchkey = PubCommon.SafeRequest(txtYongHu.Text.Trim(), 0); starttime = txtZhuCeShiJian.Text.Trim(); if (txtZhuCeShiJian.Text.Trim() != string.Empty) { endtime = (DateTime.Parse(txtZhuCeShiJian.Text.Trim()).AddDays(1)).ToShortDateString(); } Response.Redirect("UserInfoManager.aspx?searchkey=" + searchkey + "&starttime=" + starttime + "&endtime=" + endtime); } }
程序代码:
/// <summary> /// 分页 /// </summary> /// <param name="pagesize">每页记录数</param> /// <param name="pageindex">页码</param> /// <param name="docount">总记录数</param> /// <param name="sort">排序字段</param> /// <returns></returns> public static DataTable GetListPage(int pagesize, int pageindex, ref int docount, string sort, string searchkey, string starttime, string endtime, string StoredProcedureName) { SqlParameter[] parma ={ SqlHelper.ExecuteParam("@pagesize",SqlDbType.Int,pagesize,ParameterDirection.Input), SqlHelper.ExecuteParam("@pageindex",SqlDbType.Int,pageindex,ParameterDirection.Input), SqlHelper.ExecuteParam("@docount",SqlDbType.Int,docount,ParameterDirection.Output), SqlHelper.ExecuteParam("@sort",SqlDbType.VarChar,sort,ParameterDirection.Input), SqlHelper.ExecuteParam("@searchkey",SqlDbType.VarChar,searchkey,ParameterDirection.Input), SqlHelper.ExecuteParam("@starttime",SqlDbType.VarChar,starttime,ParameterDirection.Input), SqlHelper.ExecuteParam("@endtime",SqlDbType.VarChar,endtime,ParameterDirection.Input), }; DataTable dt = SqlHelper.ExecuteDataTable(CommandType.StoredProcedure, StoredProcedureName, parma); int.TryParse(parma[2].Value.ToString(), out docount); return dt; }存储过程
程序代码:
CREATE PROCEDURE UserInfo_select @pagesize int, @pageindex int, @docount int output, @sort varchar(50)='', @state int=0, @type int=0, @searchkey varchar(50)='', @starttime varchar(50)='', @endtime varchar(50)='' AS declare @mssql varchar(4000) declare @wheremssql varchar(8000) declare @R bigint, @SQL NVARCHAR(1000) set @mssql='select @R=count(id) from UserInfo ' set @wheremssql=' where 1=1 '; if(len(@searchkey)>0) begin set @searchkey=dbo.forsafe(@searchkey) set @wheremssql=@wheremssql+' and UserName like ''%'+@searchkey+'%''' end if(len(@starttime)>1) begin set @wheremssql=@wheremssql+' and RegistDateTime>='''+@starttime+'''' end if(len(@endtime)>1) begin set @wheremssql=@wheremssql+' and RegistDateTime<'''+@endtime+'''' end set @mssql=@mssql+@wheremssql SET @SQL= N' '+@mssql exec SP_EXECUTESQL @SQL, N' @R BIGINT OUTPUT', @R OUTPUT set @docount=@R set @mssql=' ' set nocount on Declare @PageLowerBound int Declare @PageUpperBound int set @PageLowerBound=(@pageindex-1)*@pagesize set @PageUpperBound=@PageLowerBound+@pagesize set rowcount @PageUpperBound--取多少条记录 set @mssql='declare @indextable table(id int identity(1,1),nid int) insert into @indextable(nid) select id from UserInfo' set @mssql=@mssql+@wheremssql if(len(@sort)<1) set @mssql=@mssql+' order by id desc' else set @mssql=@mssql+' order by '+ @sort set @mssql=@mssql+ ' select * from UserInfo O,@indextable t where O.[id]=t.nid and t.id>'+cast(@PageLowerBound as varchar)+' and t.id<='+cast(@PageUpperBound as varchar)+' order by t.id' --print(@mssql) exec(@mssql) set nocount off RETURN GO希望高手帮忙解决下!