DROP PROCEDURE IF EXISTS teach.sp_Score_Level; CREATE PROCEDURE `sp`() BEGIN declare cur_stu_id int; declare cur_course_id int; declare cur_grade varchar(10); DECLARE done INT DEFAULT 0; declare score_cur cursor for select stu_id,course_id,grade from t_score; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; open score_cur; REPEAT fetch score_cur into cur_stu_id,cur_course_id,cur_grade; if done=0 then if cur_grade>=90 then insert into t_score_level(stu_id,course_id,scorelevel) values(cur_stu_id,cur_course_id,'优'); elseif cur_grade>=70 then insert into t_score_level(stu_id,course_id,scorelevel) values(cur_stu_id,cur_course_id,'良'); elseif cur_grade>=60 then insert into t_score_level(stu_id,course_id,scorelevel) values(cur_stu_id,cur_course_id,'中'); else insert into t_score_level(stu_id,course_id,scorelevel) values(cur_stu_id,cur_course_id,'差'); end if; end if; UNTIL done=1 END REPEAT; close score_cur; select * from t_score_level; END; create table t_score_level( stu_id int, course_id int, scorelevel varchar(20)); alter table t_score_level convert to character set utf8
using (MySqlConnection conn = new MySqlConnection("server=localhost;User Id=root;password=;Database=teach")) { MySqlCommand cmd = new MySqlCommand("sp_Score_Level", conn); cmd.CommandType=CommandType.StoredProcedure; MySqlDataAdapter ad = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); ad.Fill(ds); this.dataGridView1.DataSource = ds.Tables[0]; }