Public Class frmeval
    Dim quest = Nothing
    Private Sub frmeval_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      
        mySelectQuery("SELECT t.`TEACHERSID`, t.TEACHERSNAME FROM `tblschedule` s LEFT JOIN tblteachers t on s.`TEACHERID` = t.TEACHERSID WHERE s.GRADE = " & studgrade & " GROUP BY t.TEACHERSID")
        fillcombo(cbteachersname, "TEACHERSNAME", "TEACHERSID")


        mySelectQuery(" SELECT `QUESTID`, `QUESTION` FROM `tblquestion`")
        LoadData(dgvquest, "quest")
    End Sub

    Private Sub Label5_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim TeachersID = cbteachersname.SelectedValue

        Try
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            con.Open()

            For i As Integer = 0 To dgvquest.Rows.Count - 1 Step +1

                cmd = New MySql.Data.MySqlClient.MySqlCommand("INSERT INTO `tblanswer`(`TEACHERID`, `STUDENTID`,`QUESTIONID`, `ANSWER`) VALUES (" & TeachersID & ", " & studid & ", @q, @a)")
                cmd.Parameters.Add("@q", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value = dgvquest.Rows(i).Cells(1).Value()
                cmd.Parameters.Add("@a", MySql.Data.MySqlClient.MySqlDbType.Int64).Value = dgvquest.Rows(i).Cells(2).Value()

                cmd.Connection = con
                cmd.ExecuteNonQuery()

            Next
            myInsert("INSERT INTO `tblcoments`(`TEACHERID`, `COMMENTS`, `DATE`) VALUES ( '" & Val(TeachersID) & "','" & RTBOXCOMMENTS.Text & "', NOW())")
            MsgBox("Success")
            con.Close()
        Catch ex As Exception
            MessageBox.Show("Please Answer all the Question ")

        End Try
    End Sub

   

    Private Sub cbteachersname_TextChanged(sender As Object, e As EventArgs) Handles cbteachersname.TextChanged
        Dim TeachersID = cbteachersname.SelectedValue
    
        mySelectQuery("SELECT `ID`, `SUBJECT` FROM `tblschedule` WHERE `TEACHERID`=" & TeachersID.ToString())
        fillcombo(ComboBox2, "SUBJECT", "ID")
    End Sub
End Class