Results 1 to 5 of 5

Thread: [RESOLVED] Use a DataTable from a DataSource

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    263

    Resolved [RESOLVED] Use a DataTable from a DataSource

    I added a DataSource to my project which has a few tables. If I right click a table in the "Data Sources" browser and click "preview data", in "select an object to preview" it says "timetrackerDataSet.Event.Fill" (Event is the name of the table). The problem is, I would like to make a similar call from the code:

    timetrackerDataSet.Event.Fill....

    But the only thing I am given with intellisense is

    timetrackerDataSet.EventDataTable

    And it doesn't seem to have any of the properties of a data table (the only available properties are GetDataTableSchema and GetTypedTableSchema).

    How can I get at this as a normal DataTable?

    Thanks,

    Dave

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Use a DataTable from a DataSource

    You can reference the tables collection. That will pass you back a normal DataTable:-
    timetrackerDataSet.Tables("Event")

    Is timetrackerDataSet a typed data set? If so timetrackerDataSet.EventDataTable should be passing you back specifically an Event Data Table with all the appropriate fields etc directly referencable as properties.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    263

    Re: Use a DataTable from a DataSource

    So when I tried to type it without intelisense, it said "Reference to a non-shared member requires an object reference". So I thought I needed to do:

    Code:
    Public dtEvent As New TimeTrackerData.EventDataTable
    Public daEvent As TimeTrackerDataTableAdapters.EventTableAdapter
    but now when I do
    Code:
    If dtEvent.Rows(0).Item("Companyname") = "Default" Then
    I get "there are no rows at position 0". Do I have to .Fill() the DataTable using the DataAdapter? I thought having the DataSource as part of the project would do that kind of stuff for you?

    Dave

  4. #4
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Use a DataTable from a DataSource

    Reference to a non-shared member requires an object reference
    That means you haven't instanciated it using the New keyword and explains why you weren't seeing any methods in intelli-sense.

    Do I have to .Fill() the DataTable using the DataAdapter?
    Yes

    I thought having the DataSource as part of the project would do that kind of stuff for you?
    No. You need to put it in the project before you can use it at all but you still need to tell it to populate itself at some point in your code. Bear in mind that in most scenarios you'll want to set up some parameters for your queries (like customerid, userid, that sort of thing) and you probably don't know what the values for those parameters are at design time. You'll want to set those values at runtime and then fill the data table - so you'll need to have control over when the data table gets filled. This is just one example of why you need to be able to control filling the datatable in code but as you do more you'll find there're loads of reasons.

    The best suggestion I can give is to go through the tutorials in the forum. They're really well written and help you no end. Use of data adapters, daa sets etc is actually pretty simple but only if you've grasped the basic concepts.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2004
    Posts
    263

    Re: Use a DataTable from a DataSource

    The problem was I didn't have an instance of the typed dataset created, I was trying to access properties directly on the type definition!

    Also, I started using typed data sets - they seem much cleaner.

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