创建存储过程
Create PROCEDURE MYSQL @a int, @b int, @c int output AS Set @c = @a + @b GO
通过以下方法可以获得储存过程的输出参数
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString()); conn.Open(); SqlCommand MyCommand = new SqlCommand("MYSQL", conn); MyCommand.CommandType = CommandType.StoredProcedure; MyCommand.Parameters.Add(new SqlParameter("@a", SqlDbType.Int)); MyCommand.Parameters["@a"].Value = 20; MyCommand.Parameters.Add(new SqlParameter("@b", SqlDbType.Int)); MyCommand.Parameters["@b"].Value = 20; MyCommand.Parameters.Add(new SqlParameter("@c", SqlDbType.Int)); MyCommand.Parameters["@c"].Direction = ParameterDirection.Output; MyCommand.ExecuteNonQuery(); MessageBox.Show(MyCommand.Parameters["@c"].Value.ToString());