Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataSet & DataAdapter Management
Message
 
À
14/02/2009 10:48:02
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01381602
Message ID:
01381779
Vues:
20
Hi Bonnie,

You have said here that I don't need the original DA, but also that I could pass in the SELECT statement. Isn't that one of the roles of the DA - to maintain the CommandBuilder, which in turn maintains the Insert, Update & Delete commands? It sounds like what you're saying is that a DataAdapter is able to infer from a select statement all the info it needs to do an update?



>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?
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform