|
-
Feb 23rd, 2009, 10:10 PM
#1
Thread Starter
Hyperactive Member
[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
-
Feb 24th, 2009, 04:04 AM
#2
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
-
Feb 24th, 2009, 08:11 AM
#3
Thread Starter
Hyperactive Member
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
-
Feb 24th, 2009, 09:05 AM
#4
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
-
Mar 9th, 2009, 02:46 PM
#5
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|