Populate combobox from database vb.net

Call to populate

fillUOM()
For i = 0 To uomView.Table.Rows.Count – 1
cboUOMKey.Items.Add(uomView.Item(i).Item(“uomkey”).ToString)
Next

Function to fill

Private Function fillUOM()
strCon = modDataSource.strCon_Online

Try
Dim cn As New SqlConnection(strCon)
cn.Open()

Dim strSelect As String = “select uomkey,uomdescription ” _
& “from uom”
Dim dscmd As New SqlDataAdapter(strSelect, cn)

Dim dtable As New DataTable()
dscmd.Fill(dtable)

uomView = New DataView(dtable)
cn.Close()
fillUOM = True
Catch ex As Exception
MsgBox(“Connection to database online failed.”)
fillUOM = False
End Try

End Function

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *