drop procedure if exists teach.num_from_student; create procedure teach.student_a(in dept_name varchar(20),out count_num int) begin select count(*) into count_num from t_student where stu_dept=dept_name; end ;
using (MySqlConnection conn = new MySqlConnection("server = localhost;User Id=root;password=;database=teach"))
{
MySqlCommand cmd = new MySqlCommand("student_a", conn);
cmd.CommandType = CommandType.StoredProcedure;
MySqlParameter year = new MySqlParameter("dept_name", MySqlDbType.VarChar,20);
year.Direction = ParameterDirection.Input;
year.Value =this.comboBox1.Text;
cmd.Parameters.Add(year);
MySqlParameter num = new MySqlParameter("count_num", MySqlDbType.Int16);
num.Direction = ParameterDirection.Output;
cmd.Parameters.Add(num);
conn.Open();
cmd.ExecuteNonQuery();
this.label1.Text = num.Value.ToString();
}