c#中如何使用存储过程的返回值
2007-11-19 11:08
316 查看
存储过程如下:
CREATE PROCEDURE sat_SampleReturn
AS
BEGIN
select * from UserInfo
return 50
END
GO
则在C#中使用如下代码来获得返回参数:
public static int GetSPReturnValue()
{
SqlConnection oConnection = new SqlConnection("");
oConnection.Open();
SqlCommand oCommand = new SqlCommand();
oCommand.Connection = oConnection;
oCommand.CommandType = CommandType.StoredProcedure;
oCommand.CommandText = "sat_SampleReturn";
oCommand.Parameters.Add(new SqlParameter("@Return",SqlDbType.Int));
oCommand.Parameters["@Return"].Direction=ParameterDirection.ReturnValue;
oCommand.ExecuteScalar();
oConnection.Close();
int returnValue =Convert.ToInt32( oCommand.Parameters["@Return"].Value) ;
return returnValue;
}
则会获得returnValue 为50
CREATE PROCEDURE sat_SampleReturn
AS
BEGIN
select * from UserInfo
return 50
END
GO
则在C#中使用如下代码来获得返回参数:
public static int GetSPReturnValue()
{
SqlConnection oConnection = new SqlConnection("");
oConnection.Open();
SqlCommand oCommand = new SqlCommand();
oCommand.Connection = oConnection;
oCommand.CommandType = CommandType.StoredProcedure;
oCommand.CommandText = "sat_SampleReturn";
oCommand.Parameters.Add(new SqlParameter("@Return",SqlDbType.Int));
oCommand.Parameters["@Return"].Direction=ParameterDirection.ReturnValue;
oCommand.ExecuteScalar();
oConnection.Close();
int returnValue =Convert.ToInt32( oCommand.Parameters["@Return"].Value) ;
return returnValue;
}
则会获得returnValue 为50
相关文章推荐
- C# 使用Sqlite 如何返回统计行数
- 使用ASP.NET的C#语言写后台如何将数据返回给微信小程序的JS
- 在存储过程中如何使用另一个存储过程返回的结果集
- C#使用带返回参数的存储过程
- 如何在C#中使用存储过程(SQL Server 2000)
- 在存储过程中如何使用另一个存储过程返回的结果集
- 如何在C#中使用存储过程(SQL Server 2000)
- 如何在C#中使用存储过程
- 【转】如何使用 ADO.NET 和 Visual C# .NET 调用带参数的存储过程
- C#中如何使用VC++创建的dll动态链接库的返回参数
- c#使用存储过程返回数据集(SqlCommand->DataSet)
- 如何使用 ADO.NET 和 Visual C# .NET 调用带参数的存储过程
- 如何在C#中使用存储过程(SQL Server 2000)
- c#使用存储过程返回数据集(SqlCommand->DataSet)
- 在存储过程中如何使用另一个存储过程返回的结果集
- 在存储过程中如何使用另一个存储过程返回的结果集SQL实例
- [代码]如何使用存储过程返回行集(LINQ to SQL)
- 在存储过程中如何使用另一个存储过程返回的结果集
- C#中的类SqlCommand对象使用方法ExecuteNonQuery()调用SQLServer存储过程时,存储过程执行成功,数据发生改变,但是返回-1
- c#使用存储过程返回数据集(SqlCommand->DataSet)