搜索----------存储过程
set ANSI_NULLS ONset QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[news_search]
(
@keyword varchar(50),
@publication_p varchar(50),
@type varchar(50),
@startDate varchar(50),
@endDate varchar(50)
)
as
declare @SQLStr nvarchar(200)
set @SQLStr=N'select id,type,title,important,content,publication_p,onclick,comment,regtime,edittime,category from [dbo].[news] where (CONVERT(char(10), edittime, 21) between '''+@startDate+''' and '''+@endDate+''')'
if (@keyword <>'')
set @SQLStr=@SQLStr+N' title like ''%'+@keyword+'%'''
if (@publication_p <>'')
set @SQLStr=@SQLStr+N' and title like ''%'+@publication_p+'%'''
exec sp_executesql @SQLStr
执行的时候跳出如下错误:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
第 1 行: 'title' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: 'title' 附近有语法错误。
源错误:
行 219: }
行 220: con.Open();
行 221: SqlDataReader retval = cmd.ExecuteReader(CommandBehavior.CloseConnection);
行 222:
行 223: return retval;
源文件: E:\gongzuo\huoshan\2008-06-13\HS\HS.SQLServer\SQLHelper.cs 行: 221
堆栈跟踪:
[SqlException (0x80131904): 第 1 行: 'title' 附近有语法错误。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857434
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735046
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +62
HS.SQLServer.SQLHelper.ExecuteReader(String query, SqlParameter[] parameters) in E:\gongzuo\huoshan\2008-06-13\HS\HS.SQLServer\SQLHelper.cs:221
HS.SQLServer.SQL_news.news_search1(String type, String title, String publication_p, String startDate, String endDate) in E:\gongzuo\huoshan\2008-06-13\HS\HS.SQLServer\SQL_news.cs:165
HS.BLL.B_news.search_la(String type, String title, String publication_p, String startDate, String endDate) in E:\gongzuo\huoshan\2008-06-13\HS\HS.BLL\B_news.cs:48
news_search_news.Page_Load(Object sender, EventArgs e) in e:\gongzuo\huoshan\2008-06-13\HS\web\news\search_news.aspx.cs:38
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +98
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4315
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; 版本:2.0.50727.42