帮助!我试图用我的数据库中的项目用sql语句填充列表框,我不确定如何修复此错误,因为它不断出现。我的数据库只包含两个日期,但我需要它在将来可扩展,因此数据库存储日期。
Public ds As New DataSet
Public con As New OleDb.OleDbConnection 'used to connect to the database
Public provider As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
Public datafile As String = "Resources/database.accdb" 'database location and version
Public da As OleDb.OleDbDataAdapter
Public sqlstatement As String
ds.Clear()
con.ConnectionString = connString
con.Open()
sqlstatement = "SELECT ShowDate FROM AvailableDates"
da = New OleDb.OleDbDataAdapter(sqlstatement, con)
da.Fill(ds, "Dates")
lbxDates.DisplayMember = "ShowDate"
lbxDates.DataSource = ds
lbxDates.ValueMember = "ShowDate"
con.Close()
出现错误'无法绑定到新显示成员'
lbxDates.ValueMember = "ShowDate" line
答案 0 :(得分:2)
您必须首先影响dataSource:
lbxDates.DataSource = ds.tables("Dates")
lbxDates.DisplayMember = "ShowDate"
lbxDates.ValueMember = "ShowDate"