There is combobox and few textboxes.
With the help of insert sqlcommand I can store textboxes values in the database.
But with the same insert sqlcommand I need to store one more combobox selected item too..
How to do this?

Recommended Answers

All 2 Replies

You could write a sql statement to instert each one, then place it in a loop.

Example:

    Dim conStr As String = "Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;"

    Dim con As New SqlConnection(conStr)
    Dim cmd As SqlCommand

    Try

        For i = 0 To ComboBox1.Items.Count

            con.Open()

            Dim sqls As String = "INSERT INTO table (column) VALUES ('" & ComboBox1.Items(i).ToString & "')"
            cmd = New SqlCommand(sqls, con)
            cmd.ExecuteNonQuery()

        Next


    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

I tried by myself and got it .

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.