none
Insert database row into Combobox list

    Question

  • i just found this code it was really nice, as im just a beginner i can't solve it. when i execute the code the text inside the combobox is not my database but instead a text "System.Data.DataRowView" im really newbie in vb.net im really curious how will this work. thanks in advance :)
    Private Sub FillCombo()

    1. Try
    2. Dim fillcon As New OleDbConnection(conString)
    3. Dim asql As String = ("SELECT ItemName FROM ItemMaster ORDER BY ItemName")
    4. Dim da As New OleDbDataAdapter(asql, fillcon)
    5. Dim ds As New DataSet
    6. da.Fill(ds)
    7. ItemNameCombo.ValueMember = "ItemName"
    8. ItemNameCombo.DataSource = ds.Tables(0)
    9. ItemNameCombo.SelectedIndex = 0
    10. Catch ex As Exception
    11. MsgBox("ERROR : " & ex.Message.ToString)
    12. End Try
    13. End Sub

    Tuesday, October 01, 2013 8:07 AM

Answers

  • Hello,

    Welcome to visit this forum.

    Dim fillcon As New OleDbConnection(conString)
    
    Dim asql As String = ("SELECT ItemName FROM ItemMaster ORDER BY ItemName")
    
    Dim da As New OleDbDataAdapter(asql, fillcon)
    
    Dim ds As New DataSet
    
    da.Fill(ds)
    

    The code above actually is technology named ADO.NET. It is used to operate the database as CRUD.

    The result will be like below:

    If you want to know more about the ADO.NET, please have a look at the link below:

    http://msdn.microsoft.com/en-us/library/e80y5yhx.aspx

    ItemNameCombo.ValueMember = "ItemName"
    
    ItemNameCombo.DataSource = ds.Tables(0)
    
    ItemNameCombo.SelectedIndex = 0
    

    These codes are a way for the combobox control to binding data. And it can only binding one column value.

    The result will be like below:

    And more information regarding it:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.aspx

    I notice that if it is that you want to show all or some your database columns, for that, I recommend that if it is a web app, then we can use gridview, if it is a windows form app, then we can use datagridview.

    How to use GridView:

    http://www.codeproject.com/Questions/395019/how-to-use-grid-view-with-vb-net

    How to use DataGridView:

    http://code.msdn.microsoft.com/windowsdesktop/VBWinFormDataGridView-961db2a6

    Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 02, 2013 2:39 AM
    Moderator