第一次在程序调用这玩意,百思不得其解,求高手赐教
调用方法,
public static SqlDataAdapter GetCreate()
{
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = Connection;
da.SelectCommand.CommandText="b_a('a1')"
da.SelectCommand.CommandType = CommandType.StoredProcedure;
return da;
}
SQL 存储过程
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[b_a]
@C varchar(50)
declare @sql varchar(max)
declare @where varchar(max)
set @sql='select * from user where 1=1 '
set @where=' '
select @where=@where+(case when @C is not null then ' and name like ''%'+@C+'%'''else''end)
set @sql=@sql+@where
exec(@sql)
END
页面提示:
异常详细信息: System.Data.SqlClient.SqlException: 找不到存储过程 'b_a('a1')'。
[SqlException (0x80131904): 找不到存储过程 'b_a('a1')'。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +946986
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +821638
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
------解决方案--------------------------------------------------------
da.SelectCommand.CommandText="b_a"
da.SelectCommand.Parameters.AddWithValue("@C", "a1");
----------------------------------签----------名----------栏----------------------------------
------解决方案--------------------------------------------------------
或者
da.SelectCommand.CommandText="b_a 'a'"
试试