Hi guys,
This problem is killing me!
I'm trying to get items from a table in a listbox.
I use
I call on this function with this code:
However, when I try to select an item in my listbox, I get an error saying that "conversion from String "id" to type integer is not valid. Apparently the integer is not passed to the listbox valuemember, in stead a string value is set as valuemember.
My database is very simple:
Why is this not working in the listbox?
This problem is killing me!
I'm trying to get items from a table in a listbox.
I use
to get the items in my datatablePublic Function GetItems(ByRef DisplayMember As String, ByRef ValueMember As String) As DataTable
DisplayMember = "name"
ValueMember = "id"
Sql = "SELECT id, name FROM items"
'8< snip code to connect to database and execute sql statement
DS.Tables.Add(DT)
Return DT
End Function
I call on this function with this code:
lstItems.DataSource = _clsItems.GetItems(lstItems.DisplayMember, lstItems.ValueMember)
However, when I try to select an item in my listbox, I get an error saying that "conversion from String "id" to type integer is not valid. Apparently the integer is not passed to the listbox valuemember, in stead a string value is set as valuemember.
My database is very simple:
If I try putting this in a datagridview, I get name and id as it is meant to.id->int(10) not null, auto_increment, primary key
name -> varchar(45) not null
Why is this not working in the listbox?