i wanted to know the code for putting values from comboxes into Datagridview but i tried but im getting coversion exception..

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=grade;Integrated Security=True;Pooling=False")
        Dim cmd As SqlCommand

        If ComboClass.SelectedItem <> "" Or ComboDiv.SelectedItem <> "" Or ComboSubject.SelectedItem <> "" Or ComboTeacher.SelectedItem = "" Or ComboYrstart.SelectedItem <> "" Or ComboYrEnd.SelectedItem <> "" Then


            Try
                conn.Open()
                Dim query As String = "insert into TeacherSubject(Teacher,Class,Div,Subject,YearStart,YearEnd)values(@Teacher,@Class,@Div,@Subject,@YearStart,@YearEnd)"
                cmd = New SqlCommand(query, conn)
                cmd.Parameters.AddWithValue("@Teacher", (ComboTeacher.SelectedItem()))
                cmd.Parameters.AddWithValue("@Class", (ComboClass.SelectedItem()))
                cmd.Parameters.AddWithValue("@Div", (ComboDiv.SelectedItem()))
                cmd.Parameters.AddWithValue("@Subject", (ComboSubject.SelectedItem()))
                cmd.Parameters.AddWithValue("@YearStart", (ComboYrstart.SelectedItem()))
                cmd.Parameters.AddWithValue("@YearEnd", (ComboYrEnd.SelectedItem()))

                Dim NoOfRowsAffected As Integer = cmd.ExecuteNonQuery()  //Exception of Conversion
                MessageBox.Show("Teacher-Subject Details Inserted")
                LoadDataInDataGrid()
                ComboTeacher.SelectedItem = ""
                ComboClass.SelectedItem = ""
                ComboDiv.SelectedItem = ""
                ComboSubject.SelectedItem = ""
                ComboYrstart.SelectedItem = ""
                ComboYrEnd.SelectedItem = ""


            Catch ex As Exception
                MessageBox.Show(ex.ToString())

            Finally
                If conn.State = ConnectionState.Open Then
                    conn.Close()

                End If
            End Try
        Else
            MessageBox.Show("Please fill proper details")

        End If
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.