CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2005
    Posts
    30

    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...
    Attached Images Attached Images   

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: DataAdapter help

    [ Moved to VB.NET Forum ]

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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"
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured