简单问题:存储过程返回记录!
本人初学,我要得到存储过程返回的记录,大家来帮看看!
本人存储过程如下;
CREATE PROCEDURE P_ReturnMobliePhone
@ApplicationID int,
@MobilePhone nvarchar output
as
declare @ApplicationDepartment nvarchar
declare @DepartmentTable nvarchar
declare @FunctionLevel smallint
declare @ShipType nvarchar
select @ApplicationDepartment=(select ApplicationDepartment from P_Application where ID=@ApplicationID)
select @DepartmentTable=(select DepartmentTable from Department where DepartmentID=@ApplicationDepartment)
if (@DepartmentTable= 'StationInfo ')
begin
select @FunctionLevel= '6 '
end
if (@DepartmentTable= 'ShipInfo ')
begin
select @ShipType=(select ShipType from ShipInfo where ShipID=@ApplicationDepartment)
if (@ShipType= 'ShipType001 ')
select @FunctionLevel= '4 '
if (@ShipType= 'ShipType002 ')
select @FunctionLevel= '5 '
if (@ShipType= 'ShipType003 ')
select @FunctionLevel= '5 '
end
select @MobilePhone=(select MobilePhone from Employee where FunctionLevel=@FunctionLevel)
GO
我要获取@MobilePhone参数的返回值,是这么写吗?
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings[ "my_connStr "]);
conn.Open();
SqlCommand sqlcmd=new SqlCommand();
SqlParameter my_Parameter=new SqlParameter( "@ApplicationID ",SqlDbType.Int);
my_Parameter.Value=2;
sqlcmd.Parameters.Add(my_Parameter);
SqlParameter my_return=new SqlParameter( "@MobilePhone ",SqlDbType.NVarChar,20);
my_return.Direction=ParameterDirection.Output;
my_return.Value=null;
sqlcmd.Parameters.Add(my_return);
sqlcmd.Connection=conn;
sqlcmd.CommandText= "P_ReturnMobliePhone ";
sqlcmd.CommandType=CommandType.StoredProcedure;
sqlcmd.ExecuteNonQuery();
conn.Close();
this.Response.Write(sqlcmd.Parameters[ "@MobilePhone "].Value.ToString());
为什么this.Response.Write(sqlcmd.Parameters[ "@MobilePhone "].Value.ToString());取不到值,数据库里面是有值的
------解决方案--------------------看了下你的代码感觉没什么问题..
应该是你的存储过程的问题..