Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I am trying to populate a listbox with the information from a column that is inside a table in my microsoft Access 2000 database. Also I was wondering how to delete a record from that same database..
Posted
If you are new to this like me, you may find it easier to populate the listbox at design time. I find it easier to bind the listbox to a dataset. I used the datasource property of the listbox. Im pretty sure that there are better ways, but this works for me.
Posted

This is an example of a dataset binding to a listbox

 

           Dim MyConn As New New OleDbConnection(<<CONNECTION STRING>>)
           MyConn.Open
           Dim MyAdapter As New OleDb.OleDbDataAdapter("SELECT * FROM TABLE", MyConn)
           Dim MyDataset As New DataSet() ' Create dataset
           MyAdapter.Fill(MyDataset, "TABLE") ' Fill dataset from adapter
           Listbox1.DataSource = MyDataset.Tables("TABLE") ' Set the datasource of listbox
           Listbox1.DisplayMember = "FIELDNAME" ' Set the field of the display column
           Listbox1.ValueMember = "ID" ' Set the field of the ID field (Optional)
           ' Cleanup code
           MyDataset.Dispose
           LendersAD.Dispose 

 

Thats for databinding Make sure you substitue your own connection string SQL and Fieldnames

 

Andy

Code today gone tomorrow!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...