C#接收存储过程返回值和输出参数
2010-04-06 14:17
387 查看
C#接收存储过程返回值:
public static int User_Add(User us)
{
int iRet;
SqlConnection conn = new SqlConnection(Conn_Str);
SqlCommand cmd = new SqlCommand("User_Add", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UName", us.UName);
cmd.Parameters.AddWithValue("@UPass", us.UPass);
cmd.Parameters.AddWithValue("@PassQuestion", us.PassQuestion);
cmd.Parameters.AddWithValue("@PassKey", us.PassKey);
cmd.Parameters.AddWithValue("@Email", us.Email);
cmd.Parameters.AddWithValue("@RName", us.RName);
cmd.Parameters.AddWithValue("@Area", us.Area);
cmd.Parameters.AddWithValue("@Address", us.Address);
cmd.Parameters.AddWithValue("@ZipCodes", us.ZipCodes);
cmd.Parameters.AddWithValue("@Phone", us.Phone);
cmd.Parameters.AddWithValue("@QQ", us.QQ);
cmd.Parameters.Add("@RETURN_VALUE", "").Direction = ParameterDirection.ReturnValue;
try
{
conn.Open();
cmd.ExecuteNonQuery();
iRet = (int)cmd.Parameters["@RETURN_VALUE"].Value;
return iRet;
}
catch (SqlException ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
C#接收存储过程输出参数:
public static decimal Cart_UserAmount(int UID)
{
decimal iRet;
SqlConnection conn = new SqlConnection(Conn_Str);
SqlCommand cmd = new SqlCommand("Cart_UserAmount", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UID", UID);
cmd.Parameters.Add("@Amount", SqlDbType.Decimal).Direction=ParameterDirection.Output;
try
{
conn.Open();
cmd.ExecuteNonQuery();
iRet = (decimal)cmd.Parameters["@Amount"].Value;
return iRet;
}
catch (SqlException ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wwlearn/archive/2008/05/23/2474525.aspx
public static int User_Add(User us)
{
int iRet;
SqlConnection conn = new SqlConnection(Conn_Str);
SqlCommand cmd = new SqlCommand("User_Add", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UName", us.UName);
cmd.Parameters.AddWithValue("@UPass", us.UPass);
cmd.Parameters.AddWithValue("@PassQuestion", us.PassQuestion);
cmd.Parameters.AddWithValue("@PassKey", us.PassKey);
cmd.Parameters.AddWithValue("@Email", us.Email);
cmd.Parameters.AddWithValue("@RName", us.RName);
cmd.Parameters.AddWithValue("@Area", us.Area);
cmd.Parameters.AddWithValue("@Address", us.Address);
cmd.Parameters.AddWithValue("@ZipCodes", us.ZipCodes);
cmd.Parameters.AddWithValue("@Phone", us.Phone);
cmd.Parameters.AddWithValue("@QQ", us.QQ);
cmd.Parameters.Add("@RETURN_VALUE", "").Direction = ParameterDirection.ReturnValue;
try
{
conn.Open();
cmd.ExecuteNonQuery();
iRet = (int)cmd.Parameters["@RETURN_VALUE"].Value;
return iRet;
}
catch (SqlException ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
C#接收存储过程输出参数:
public static decimal Cart_UserAmount(int UID)
{
decimal iRet;
SqlConnection conn = new SqlConnection(Conn_Str);
SqlCommand cmd = new SqlCommand("Cart_UserAmount", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UID", UID);
cmd.Parameters.Add("@Amount", SqlDbType.Decimal).Direction=ParameterDirection.Output;
try
{
conn.Open();
cmd.ExecuteNonQuery();
iRet = (decimal)cmd.Parameters["@Amount"].Value;
return iRet;
}
catch (SqlException ex)
{
throw ex;
}
finally
{
conn.Close();
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wwlearn/archive/2008/05/23/2474525.aspx
相关文章推荐
- C#接收存储过程返回值和输出参数
- C#接收存储过程返回值和输出参数
- C#调用存储过程 之返回值与输出参数的区别与用法实例
- C#调用存储过程详解(带返回值、参数输入输出等)
- C#调用存储过程 之返回值与输出参数
- C#获取存储过程返回值和输出参数值
- C#调用存储过程 之返回值与输出参数
- ASP.NET调用存储过程返回输出参数,获得返回值
- C#后台给某网址传递参数,并接收返回值
- c#调用带输出参数的存储过程
- C# 读取存储过程输出参数,始终是常数问题,原来是C#定义输出参数时,定义格式的问题
- C#里调用带输出参数的存储过程
- C# 调用带输入输出参数的存储过程
- C#获取存储过程的 Return返回值和Output输出参数值
- C#调用存储过程 返回值,输出参数,返回结果集
- 关于C#调用存储过程,带输出参数,存储过程
- asp.net 存储过程 输入输出参数+返回值
- 如何在SQL Server中定义带返回值的存储过程,然后被c# entity 模型接收?
- C#接收存储过程返回值
- C#使用ExecuteReader返回DataReader既有查询结果集又有输出参数或返回值的使用注意事项