VB.NET组合框显示带有Access数据库的System.Data.DataRowView

时间:2016-01-08 18:08:43

标签: vb.net combobox

我正在使用以下代码。运行时,组合框显示System.Data.DataRowView而不是数据库中的项名称

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
        Dim fillcon As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\tcs.accdb")

        Dim asql As String = ("SELECT ItemName FROM Items ORDER BY ItemName")
        Dim da As New OleDbDataAdapter(asql, fillcon)
        Dim ds As New DataSet
        da.Fill(ds)
        ComboBox1.ValueMember = "ItemName"
        ComboBox1.DataSource = ds.Tables(0)
        ComboBox1.SelectedIndex = 0
    Catch ex As Exception
        MsgBox("ERROR : " & ex.Message.ToString)
    End Try

End Sub

1 个答案:

答案 0 :(得分:0)

您需要为要查询的某个字段指定.DisplayMember