-
October 5th, 2009, 05:40 AM
#1
DataAdapter help
I have a problem with access database in my vb project. I would like to fill the listbox with objects from my database.
I've attached two images. In first image when i'm using command objDataAdapter.Fill(mydataset....) i can select table property(zaposlen). But in second image or in my second app i dont have an option to select table property in my dataset(there is nothing to select). If i select DataTableDataTable i get next error: DataTableDataTable' is a type in 'WindowsApplication1.baza_podatkovDataSet' and cannot be used as an expression.
I would like some help with this matter. How can i get a selection in a second image like i have it in first one? Thanks...
-
October 5th, 2009, 05:43 AM
#2
Re: DataAdapter help
[ Moved to VB.NET Forum ]
-
October 5th, 2009, 05:50 PM
#3
Re: DataAdapter help
Try this: (modify to suit)
Code:
Dim adapter As New SqlDataAdapter("SELECT FieldName, AnotherFieldName FROM Table", connection)
'Create a DataTable object to hold the data returned via the DataAdapter
Dim dt As New DataTable("TableName")
'Use the Fill method of the DataAdapter to populate the DataTable. Note that
'the Fill method will handle the opening and closing of the database connection
'for you, although should you need to do this manually then simply call the
'connection.Open and connection.Close methods.
adapter.Fill(dt)
'Now that you have the data in the DataTable, you can assign the DataTable
'to the DataSource property of the ListBox
ListBox1.DataSource = dt
'At this point you will also want to set the DisplayMember and ValueMember
'properties of the ListBox so that you can state which field is used for
'display and which field is used for the value (usually the primary key of the
'table).
ListBox1.ValueMember = "PrimaryKeyFieldName"
ListBox1.DisplayMember = "FieldNameForDisplay"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|