麻烦大家帮忙看一下原因: 
private void InputGrade_Click(object sender, EventArgs e) 
        { 
            try 
            {                 DataSet StuGrdClaDS = new DataSet(); 
                string StuGrdStrConnSql = "Select course.course_id,student.student_id from student,class,student_course,course where student.class_id=class.class_id and class.class_name=" + "'" + this.QSGStuClass.SelectedItem.ToString().Trim() + "'" + "and student.student_name=" + "'" + this.QSGStuName.Text.ToString().Trim() + "'" + "and course.course_name=" + "'" + this.QSGStuCourse.SelectedItem.ToString().Trim() + "'"; 
                this.QSGConn = new SqlConnection(this.QSGStrConn); 
                this.QSGsqlda = new SqlDataAdapter(StuGrdStrConnSql, this.QSGConn); 
                StuGrdClaDS.Clear(); 
                this.QSGsqlda.Fill(StuGrdClaDS, "Class"); 
              string courId = StuGrdClaDS.Tables[0].Rows[0][0].ToString().Trim(); 
                string StuId = StuGrdClaDS.Tables[0].Rows[0][1].ToString().Trim();                                  QSGStrComd = "insert into Student_course(Student_id,Course_id,Grade,SC_semester,School_year,Pga)values" + "(" + "'" + StuId + "'" + "," + "'" + courId + "'" + "," + "'" + this.QSGStuGrade.Text.ToString().Trim() + "'" + "," + "'" + this.SchoolYear.Text.ToString().Trim() + "'" + "," + "'" + this.SchoolSemester.Text.ToString().Trim() + "'" + "," + "'" + this.QSGStuPga.Text.ToString().Trim() + "'" + ")"; 
                    QSGConn = new SqlConnection(QSGStrConn); 
                    QSGConn.Open(); 
                    QSGComd = new SqlCommand(QSGStrComd, QSGConn); 
                    int Sucnum = QSGComd.ExecuteNonQuery(); 
                    if (Sucnum > 0) MessageBox.Show("录入成功"); 
                } 
                        catch (Exception Eq) 
            { 
                MessageBox.Show(Eq.ToString(), "提示", MessageBoxButtons.YesNo); 
            } 
        } 
                } 
            } 
捕获异常显示:在位置0处没有任何行~通过断点测试到红色字体有错~~为什么会这样啊?该怎么解决啊? 
~麻烦大哥哥大姐姐帮小弟一下!跪谢了 ~

解决方案 »

  1.   


    if(StuGrdClaDS!=null&&StuGrdClaDS.Tables[0].Rows.Count>0)
    {
                  string courId = StuGrdClaDS.Tables[0].Rows[0][0].ToString().Trim(); 
                    string StuId = StuGrdClaDS.Tables[0].Rows[0][1].ToString().Trim();      
    }
      

  2.   

    哇哈哈~1楼的大哥好幽默哦~不过高手还是能看出我的错误时在哪里的~我照您的方法添加以后,这里的红色字体却说不存在喔?(这次真有红字了)QSGStrComd = "insert into Student_course(Student_id,Course_id,Grade,SC_semester,School_year,Pga)values" + "(" + "'" + StuId + "'" + "," + "'" + courId + "'" + "," + "'" + this.QSGStuGrade.Text.ToString().Trim() + "'" + "," + "'" + this.SchoolYear.Text.ToString().Trim() + "'" + "," + "'" + this.SchoolSemester.Text.ToString().Trim() + "'" + "," + "'" + this.QSGStuPga.Text.ToString().Trim() + "'" + ")"; ~高手别笑我..