读书人

.net与存储过程的返回值?解决办法

发布时间: 2012-04-08 14:38:30 作者: rapoo

.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();
Da.Fill(ds);


return ds;
}
catch (Exception e)
{
throw new Exception(e.Message);
}

再往下不知该怎么写了,帮忙给解决一下吧??




[解决办法]
param = new SqlParameter( "@ReturnValue ", SqlDbType.VarChar);

param.Direction = ParameterDirection.ReturnValue;

rowcount = param.Value ;
[解决办法]
需要一个数组参数SqlParameter[] Sqlparam;
Sqlparam=new SqlParameter[2];
Sqlparam[0]=Datalink.CreateInParam( "@Page ",SqlDbType.Int,0,1);
Sqlparam[1]=Datalink.CreateInParam( "@Num ",SqlDbType.Int,0,4);

读书人网 >asp.net

热点推荐