Enterprise Library, DataSets, and Windows Forms binding.

A

Alan B

Okay so I'm using the Data Access application block in the Enterprise
Library. I'm using it to return a DataSet from an SQL Server (well, MSDE)
stored procedure. So that's an untyped DataSet. I have no access to the
DataAdapter used to retrieve the DataSet (the Enterprise Library classes
don't expose it AFAIK), so I can't create any TableMappings. I want to bind
the DataSet to Windows Forms controls, but I'm getting the old 'cannot
create child list' errors because there's no schema attached to the DataSet.
I can manually name tables and columns in the DataSet via the Tables
collection, and then bind. This is messy though, so:

1) Is that the only way to do it?
2) If I retrieve the DataSet, then use WriteXMLSchema, can I subsequently
use that saved schema against the returned DataSet?
3) This must be a very common thing that people need to do - why is is such
a pain in ADO.NET?
 
K

Keenan Newton

Use the LoadDataSet method of the Database class. Some of the
overloads for this method contains a parameter that accepts a string
array of tablenames, used for tablemapping. the one thing you have to
be aware of is that you need to pass in a Dataset to make this happen,
as opposed ot the ExecuteDataSet method where it creates it inside the
methods implementation.
 
P

post messages

Alan B said:
Thanks Keenan ... so many ways to do things in .NET, LOL ....

I looked at the source code of LoadDataSet which ultimately calls
DoLoadDataSet. Yes the tablemappings are applied but that has nothing
to do with schema (primary keys, other constraints). The only way I
know of to get that information is to call FillSchema. Nowhere in the
Enterprise Library (from searching the code) does it use FillSchema.
It also does not expose DataAdapters of which FillSchema is a method.

So one choice is to put code in your data layer to create an adapter
and fill the schema. This now means breaking that line of abstraction
as you now need a reference to OleDBAdapter or Ora or Sql, etc.

I am going to hack my copy of DoLoadDataSet to do the FillSchema
there.

Regards,
Post (ya I know, silly name to sign with but I like that layer of
abstraction from spammers).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top