0

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?

2
Contributors
2
Replies
10
Views
5 Years
Discussion Span
Last Post by Iamateur
0

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

Edited by Begginnerdev: edit

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.