/* ###################### 要求三 ###################### */ private void AddBtn_Click(object sender, EventArgs e) { Intent.STATE = "ADD"; StudentEdit se = new StudentEdit(); if (se.ShowDialog() == DialogResult.OK) { Student s = se.s; sql = @"" + " INSERT INTO [Student]" + " VALUES" + " (@SNo, @SName, @Date, @classNo)"; SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@SNo", s.SNo), new SqlParameter("@SName", s.SName), new SqlParameter("@Date", s.Date), new SqlParameter("@classNo", s.classNo), }; table = db.GetBySQL(sql, sqlParams); } LoadTabs(); }
private void ChangeBtn_Click(object sender, EventArgs e) { Intent.STATE = "CHANGE"; if (listView3.SelectedItems.Count == 0) { MessageBox.Show("请选择一行"); return; } Student s = new Student(); s.SetValue( listView3.SelectedItems[0].SubItems[0].Text, listView3.SelectedItems[0].SubItems[1].Text, listView3.SelectedItems[0].SubItems[2].Text, listView3.SelectedItems[0].SubItems[3].Text ); StudentEdit se = new StudentEdit(); se.s = s; Intent.OLD_ID = s.SNo; if (se.ShowDialog() == DialogResult.OK) { sql = @"" + " UPDATE [Student]" + " SET" + " [Sno]=@SNo," + " [SName]=@SName," + " [Date]=@Date," + " [classNo]=@classNo" + " WHERE [Sno]=@OLD_ID"; SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@SNo", s.SNo), new SqlParameter("@SName", s.SName), new SqlParameter("@Date", s.Date), new SqlParameter("@classNo", s.classNo), new SqlParameter("@OLD_ID", Intent.OLD_ID.ToString()) }; table = db.GetBySQL(sql, sqlParams); } LoadTabs(); }