hello, i have a problem with combobox to stored in sql database

this is my code

cmbDept.Items.Add("" & dtUser.Rows(i).Item(0) & "/" & dtUser.Rows(i).Item(1) & "")

how to take the first item from combobox "dtUser.Rows(i).Item(0)"
and stored in sql database. ??

Recommended Answers

you want to concatinate multiple values from DB and add to combo?

Jump to Post

All 4 Replies

you want to concatinate multiple values from DB and add to combo?

no, I mean how to insert to database the first value of combobox

Private Sub LoadDept()
        conn = New SqlConnection("Data Source=EXCO-2B41B5;Initial Catalog=payroll;Integrated Security=True")
        cmdUser = conn.CreateCommand
        cmdUser.CommandText = "select * from department order by number asc"
        daUser.SelectCommand = cmdUser
        daUser.Fill(dsUser, "department")
        dtUser = dsUser.Tables("department")
        For i = 0 To dtUser.Rows.Count - 1
            cmbDept.Items.Add("" & dtUser.Rows(i).Item(0) & "/" & dtUser.Rows(i).Item(1) & "")
        Next i
        conn.Close()
End Sub

Item(0) = first field is "number"
Item(1) = second field "division"

result in combobox
1/Injection
2/Warehouse
3/Maintenance

my question is how to insert database just the fisrt value, that is Item(0) "number"

Any kind of help would be appreciated.

You want to insert the selected value in combobox? or all?

yes. the selected value, but i want to insert first item in combobox, not both.
in my code, the first item is cmbDept.Items.Add("" & dtUser.Rows(i).Item(0) &"")

first item / second item
----------- ------------
1 / Injection
2 / Warehouse
3 / Maintenance

Be a part of the DaniWeb community

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