- 爱易网页
-
ASP.NET教程
- .net与存储过程的返回值?解决办法
日期:2014-05-18 浏览次数:20611 次
.net与存储过程的返回值?
我想实现下面的功能:
通过下面的存储过程:
CREATE PROCEDURE search
(
@txt varchar(500),
@n varchar
)
AS
if @n= "1 "
select * from table1 where Title like '% '+@txt+ '% '
if @n= "2 "
select * from table1 where Content like '% '+@txt+ '% '
return @@Rowcount
GO
获得查到的数据和返回值(ds和@@Rowcount)
下面是.net的
str与n都传过来.
SqlConnection conn = new SqlConnection(strConn);
SqlDataAdapter Da = new SqlDataAdapter();
Da.SelectCommand = new SqlCommand();
Da.SelectCommand.Connection = conn;
Da.SelectCommand.CommandText = "search ";
Da.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlParameter param;
param = new SqlParameter( "@txt ", SqlDbType.VarChar,500);
param.Direction = ParameterDirection.Input;
param.Value = str;
Da.SelectCommand.Parameters.Add(param);
param = new SqlParameter( "@n ", SqlDbType.VarChar);
param.Direction = ParameterDirection.Input;
param.Value = n;
Da.SelectCommand.Parameters.Add(param);
//rowcount = Da.SelectCommand.Parameters
try
{
DataSet ds = new DataSet();