c#中获取存储过程的返回值(return Value)

  • Post author:
  • Post category:其他



string


connStr = “server=kofo;database=pubs;uid=sa;pwd=kofo123”;




SqlConnection myConnection =

new

SqlConnection(connStr);





try




{




myConnection.Open();




SqlCommand myCommand =

new

SqlCommand(“TestRetValue”,myConnection);




myCommand.CommandType = CommandType.StoredProcedure;




SqlParameter myParam = myCommand.Parameters.Add(

new

SqlParameter(“@RETURN_VALUE”,SqlDbType.Int,4));







myParam.Direction = ParameterDirection.ReturnValue;





myCommand.ExecuteNonQuery();





int

me = (

int

)myParam.Value;




MessageBox.Show(me.ToString());







}





catch

(Exception ex)




{




MessageBox.Show(ex.Message);




}





finally




{




myConnection.Close();




}




版权声明:本文为mane_yao原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。