Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataSet & DataAdapter Management
Message
From
14/02/2009 10:48:02
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01381602
Message ID:
01381752
Views:
27
I don't typically use the DataAdapter.Update() method (I roll my own update), but I can still help you out here I think.

>A DataSet is filled from a DataAdapter. Therefore, to call the Update and send changed back to the DB, I must use the SAME DataAdpater?

No, it does not have to be the same DataAdapter. But, if you're going to use the .Update() method, the DataAdapter needs to know the INSERT, UPDATE and DELETE commands associated with the SELECT. I assume you're setting these somehow, either manually or by using the CommandBuilder (which I also do not use).

So, perhaps what you can do is to overload your MyClass.Update() method with a signature that accepts the original SELECT as a second parameter. In this overload, you could use the CommandBuilder (or whatever way you're currently using), based on the parameter. So, in that way you could use it like this:
DataSet ds1 = MyClass.ExecuteQuery("selec * from books");
DataSet ds2 = MyClass.ExecuteQuery("selec * from CDs");
DataSet ds3 = MyClass.ExecuteQuery("selec * from Tapes");

ds3.Tables[0].Rows[1]['name'] = 'Whatever';
MyClass.Update(ds3);

ds1.Tables[0].Rows[1]['name'] = 'Some Name';
MyClass.Update(ds1, "selec * from books");
Not the greatest solution, but one that should work given the way you've currently laid out your class.

~~Bonnie





>I am a bit unsure about how something works.
>
>A DataSet is filled from a DataAdapter. Therefore, to call the Update and send changed back to the DB, I must use the SAME DataAdpater?
>
>If this is true, then my DataAccess class has a design flaw. I have the following at the top of my class:
>
>
>private SqlDataAdapter _DA;
>
>
>
>Then in the ExecuteQuery method I have:
>
>
>// Create a DataAdapter, passing in the command class
>_oAdapter = new SqlDataAdapter(oCommand);
>
>// The DS
>DataSet oDataSet = new DataSet();
>
>// Fill the data set
>try
>{
>    _DA.Fill(oDataSet, sTableName);
>
>}
>catch (Exception e)
>{
>    _oException = e;
>}
>
>
>
>Here's the question - If the DataSet requires the SAME DataAdapter to update changes to the DB, then I can only ever make one call to this ExecuteQuery method. I could not use this class to have multipe DataSets returned, because each subsequent call to ExecuteQuery would create a new DataAdpter into _DA, losing the previous reference. Then, any DataSets generated in the past would not be able to be updated because their DataAdapter has been lost.
>
>Another words, I could not do:
>
>
>DataSet ds1 = MyClass.ExecuteQuery("selec * from books");
>DataSet ds2 = MyClass.ExecuteQuery("selec * from CDs");
>DataSet ds3 = MyClass.ExecuteQuery("selec * from Tapes");
>
>ds1.Tables[0].Rows[1]['name'] = ''Some Name';
>MyClass.Update(ds1);
>
>
>Because the second and third calls lost the reference to their DA's
>
>
>Or am I the one who's lost?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform