Example #1
0
 //查询按钮
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (FormMain.Power == "学生")
         {
             DBOperate operate = new DBOperate();
             string    name    = operate.GetName();
             string    str1    =//创建查询字符串
                                 "select A.stu_class as 班级,A.stu_id as 学号,A.stu_name as 姓名,B.Cour_Name as 课程名,B.Score as 成绩 from Student as A JOIN SC_result AS B ON A.stu_id=B.Stu_Id join Coures as C ON C.Cour_Id=B.Cour_Id where A.stu_name='" + name + "' and C.Cour_Semester='" + cbbSemester.SelectedItem.ToString() + "' and B.Cour_Name='" + cbbCourse.SelectedItem.ToString() + "'";
             operate.BindDataGridView(dataGridView1, str1);
         }
         else
         {
             if (cbbCourse.Text == "")
             {
                 string str =//创建查询字符串
                              "select A.stu_class as 班级,A.stu_id as 学号,A.stu_name as 姓名,B.Cour_Name as 课程名,B.Score as 成绩 from Student as A JOIN SC_result AS B ON A.stu_id=B.Stu_Id join Coures as C ON C.Cour_Id=B.Cour_Id where A.stu_name='" + cbbstudent.SelectedItem.ToString() + "' and C.Cour_Semester='" + cbbSemester.SelectedItem.ToString() + "' and A.Stu_class='" + cbbClass.SelectedItem.ToString() + "'";
                 operate.BindDataGridView(dataGridView1, str);
             }
             else
             {
                 string str =                                  //创建查询字符串
                              "select A.stu_class as 班级,A.stu_id as 学号,A.stu_name as 姓名,B.Cour_Name as 课程名,B.Score as 成绩 from Student as A JOIN SC_result AS B ON A.stu_id=B.Stu_Id join Coures as C ON C.Cour_Id=B.Cour_Id where B.Cour_Name='" + cbbCourse.SelectedItem.ToString() + "' and C.Cour_Semester='" + cbbSemester.SelectedItem.ToString() + "' and A.Stu_class='" + cbbClass.SelectedItem.ToString() + "'";
                 operate.BindDataGridView(dataGridView1, str); //将查询信息绑定到DATAGRIDVIEW控件
             }
         }
     }
     catch
     {
         MessageBox.Show("你还有未选择的项", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }