tring SqlText = \学生编号,sname as 学生姓名,sc.cno as 课程号,cname as 课程名,grade as 成绩 from student , course , sc where student.sno=sc.sno and sc.cno=course.cno and student.sno like '\+ this.textBox_sno.Text.Trim() + \and student.sname like '%\+ this.textBox_sname.Text.Trim() + \course.cname like '%\+ this.text_cname.Text.Trim() + \and student.sdept like '%\+ this.text_dept.Text.Trim()
+
\
course.cno
like
'%\
+
this.textBox_cno.Text.Trim() + \ DataAccess DA = new DataAccess(); this.dt = DA.ExeSQLdt(SqlText);
this.dataGridView.DataSource = this.dt.DefaultView; this.cm = (CurrencyManager)BindingContext[this.dt]; dataGridView.Columns[\课程号\ dataGridView.Columns[\学生编号\ dataGridView.Columns[\学生姓名\ dataGridView.Columns[\课程名\ if (this.dataGridView.Rows.Count != 0) {
for (int i = 0; i < this.dataGridView.Rows.Count; ) {
this.dataGridView.Rows[i].DefaultCellStyle.BackColor System.Drawing.Color.Pink; i += 2; } } ②增加操作
用到的sql语句:
insert into course values ('课号','课程名','先行课号','学分');或insert into course(cno,cname,ccredit) values ('课号','课程名','学分');
=
if (textBox_cno.Text != \&& textBox_ccredit.Text != \&&
textBox_cname.Text != \
{
string SqlText = \ SqlText += \ DataAccess DA = new DataAccess(); if (DA.IsRead(SqlText) == false) {
if (this.textBox_cpno.Text != \ {
SqlText = \ SqlText += \
+ this.textBox_cname.Text.Trim() + \
SqlText += int.Parse(this.textBox_cpno.Text.Trim()) +
\
DA = new DataAccess(); if (DA.ExeSQL(SqlText) == 1) {
DialogResult result = MessageBox.Show(\新增课程
成功!是否返回课程表?\提示!\
MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) {
_013student.FormCourse.formcourse.DBDataGrid();
this.Close(); }
if (result == DialogResult.No) {
return; } } } else {
SqlText = \values (\
SqlText += \\
SqlText += this.textBox_ccredit.Text.Trim() + \
DA = new DataAccess(); if (DA.ExeSQL(SqlText) == 1) {
// MessageBox.Show(\新增课程成功!\ DialogResult result = MessageBox.Show(\新增课程
成功!是否返回课程表?\\提示!\MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes) {
_013student.FormCourse.formcourse.DBDataGr
id();
this.Close(); }
if (result == DialogResult.No) {
return; } } } } else {
MessageBox.Show(\课程号已存在请重新输入\ } } else {
MessageBox.Show(\课程号、课程名或学分不能为空\ } }
③修改操作
用到的sql语句:
update course set cname = '修改后的课程名' , cpno = '先行课号' ,ccredit = '学分'where cno = '当前选中行的课号';
if (this.dataGridView.Rows.Count != 0) {
DataAccess DA = new DataAccess();
string SqlText = \course set cname = '\
+this.dataGridView[1,this.dataGridView.CurrentCellAddress.Y].Value.ToString() + \, cpno = '\+ this.dataGridView[2,this.dataGridView.CurrentCellAddress.Y].Value.ToString() + \,ccredit = '\+ this.dataGridView[3,this.dataGridView.CurrentCellAddress.Y].Value.ToString() + \cno = '\+ this.dataGridView[0,this.dataGridView.CurrentCellAddress.Y].Value.ToString() + \
DA.ExeSQL(SqlText);
MessageBox.Show(\修改成功!\ this.DBDataGrid(); }
④删除操作
用到的sql语句:
先 delete from sc where cno = ‘当前选中行的课号’;