Sahil
Mon Jan 03 22:12:11 CST 2005
> However, there's not updatable view concept in ADO.NET.
> If I do a JOIN to any lookup tables, CommandBuilder flatlines and can't
> generate the necessary update statements. Is the only alternative here to
> generate the update statement by hand? That just seems incredibly tedious
> and
> unnecessary.
CommandBuilder is hyper inefficient for flat tables too. Update Statements
by hand is the best, not so tedious and fairly necessary.
> Another weird thing is that it's a mystery as to how CommandBuilder works.
> If you trace through the code you'll see that it doesn't actually modify
> the
> UpdateCommand property in the DataAdapter. Somehow it's doing it's magic
> in
> the background. This prevented me from kludging up update statements from
> a
> non-lookup version of the SelectCommand and using that in the lookup
> version.
CommandBuilder works based upon the schema of your table and tries and
generates the best possible one size fits all kinda SQL Query, as mentioned
above it is okay for a quick and dirty job, but not for a heavy load
enterprise app.
> Another problem is now to specify a primary key for the DataSet.
> Supposedly
> the SqlDataAdapter uses a DataReader in the background to generate schema
> for
> the DataSet. But the IsKey fields are all null. So somewhere between there
> and the DataSet it somehow decides what the primary key is, but it's not
> accessible to the programmer. I guess what I'm wonder is can I specify a
> primary key directly to the DataSet after it has been filled?
SqlDataAdapter uses DataReader - that's a comment I have never been able to
validate, maybe the MS Gurus can shed light on that. Though I have heard the
same many times over, I'm just not sure if it's air talk or has weight to
it.
DataSet can hold schema information if you call a FillSchema on it first. In
my opinion FillSchema executes a fairly heavy query on the master db so it
should be avoided in heavy duty operations.
Yes you can emulate PK in a DataTable after or before it has been filled.
There are properties on the relevant datacolumn object that allow you to do
this very easily.
.. and don't be frustrated, in the long run ADO.NET is way better than ADO.
I recommend buying a book :-) (hint hint google for my name).
- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"pearsons_11114" <pearsons11114@discussions.microsoft.com> wrote in message
news:074318A5-8C13-453F-8C32-6E972B359FBB@microsoft.com...
> Switching from ADO to ADO.net and I am totally lost and and frustrated.
> What
> I'm trying to do is so dirt simple: At RUNTIME, load an arbitrary database
> table into a datagrid for editing. Simple: create a SqlDataAdapter,
> dynamically constructing the SQL command string based on the the name of
> the
> table supplied at runtime; create a CommandBuilder; call Fill, supplying a
> new blank DataSet; call Update when complete. So far, so good.
>
> The table that I'm editing has lookups that the user needs to be able to
> see
> as they are editing. However, there's not updatable view concept in
> ADO.NET.
> If I do a JOIN to any lookup tables, CommandBuilder flatlines and can't
> generate the necessary update statements. Is the only alternative here to
> generate the update statement by hand? That just seems incredibly tedious
> and
> unnecessary.
>
> Another weird thing is that it's a mystery as to how CommandBuilder works.
> If you trace through the code you'll see that it doesn't actually modify
> the
> UpdateCommand property in the DataAdapter. Somehow it's doing it's magic
> in
> the background. This prevented me from kludging up update statements from
> a
> non-lookup version of the SelectCommand and using that in the lookup
> version.
>
> Another problem is now to specify a primary key for the DataSet.
> Supposedly
> the SqlDataAdapter uses a DataReader in the background to generate schema
> for
> the DataSet. But the IsKey fields are all null. So somewhere between there
> and the DataSet it somehow decides what the primary key is, but it's not
> accessible to the programmer. I guess what I'm wonder is can I specify a
> primary key directly to the DataSet after it has been filled?
>