private void BtnAddClick(object sender, EventArgs e) { foreach (Control c in gbox.Controls) { if (c is TextBox && c.Text == string.Empty) { MessageBox.Show("请输入学生的完整信息!"); return; } if (c == inf3 && ((ComboBox)c).SelectedIndex == -1) { MessageBox.Show("请输入学生的完整信息!"); return; } if (c == inf4 && (!int.TryParse(c.Text, out int age) || age < 10 || age > 50)) { MessageBox.Show("学生年龄无效,请重新输入!"); c.Text = string.Empty; return; } } string cmd = $"insert into students(sid,sname,gender,enage,grade,class) values('{inf1.Text}','{inf2.Text}','{inf3.SelectedItem}',{inf4.Text},{inf5.Text},'{inf6.Text}');"; DBO.Insert(cmd); MessageBox.Show("插入成功!"); }
private void BtnAddClick(object sender, EventArgs e) { foreach (Control c in gbox.Controls) { if (c is TextBox && c.Text == string.Empty) { MessageBox.Show("请输入选课的完整信息!"); return; } } string cmd = $"insert into register(sid,cid,ryear,score) values('{inf1.Text}','{inf2.Text}',{inf3.Text},{inf4.Text});"; DBO.Insert(cmd); MessageBox.Show("插入成功!"); }
private void BtnAddClick(object sender, EventArgs e) { foreach (Control c in gbox.Controls) { if (c is TextBox && c != inf6 && c.Text == string.Empty) { MessageBox.Show("请输入课程的完整信息!"); return; } } string cmd = $"insert into courses(cid,cname,tname,credit,grade,cyear) values('{inf1.Text}','{inf2.Text}','{inf3.Text}',{inf4.Text},{inf5.Text},{(inf6.Text == string.Empty ? "null" : inf6.Text)});"; DBO.Insert(cmd); MessageBox.Show("插入成功!"); }