Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Force DataSet.HasChanges to True
Message
De
01/02/2010 07:03:57
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
31/01/2010 18:11:13
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 3.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01446548
Message ID:
01446867
Vues:
32
>>I am pulling a dataset from a SQL Database and I want to move into a VistaDB table with the exact same structure. So what I need to do is fill my dataset from SQL server but when I try to then set that dataset to be saved to the different datasource it will not save because nothing was changed. There could be 25 rows or some tables may have a couple thousand rows. I would prefer not to loop through the rows but it isn't a big performance hit in this case. I have several tables that will need to be exported so I have a selector to pick the tables to be moved. I just need to figure out how to put the dataset in a state that will allow me to save it all again.
>
>And that all depends on what mechanism you're using to save your datasets. If you're relying on the DataAdapter.Update() command, then yeah, you'll have to actually have changes for every row you want to save ... and unfortunately, making those changes as I showed you isn't going to do a darn thing for you. That's because the RowState will be Modified, but you actually want the RowState to be Added.
>
>So, given *that* requirement, what you really need to do, for each row in each table, is use the .SetAdded() method, which changes the RowState to Added:
>
>
>foreach(DataTable dt in MyDataSet)
>    foreach(DataRow row in dt)
>        row.SetAdded();
>
>
>Then you can use the DataAdapter.Update() as usual.
>
>However, you can also "roll your own" DataAccess such that you really don't care what the RowState is, you'll simply Insert each row in each table into your database. I use this methodology, mainly because I have to since I pass data through a webservice as an XML string, which contains no RowState. If you're interested in some thoughts on how to do that, you can take a look at my DataAccess series of posts on my blog:

Hi Bonnie,

I am using the MM framework Business objects but this is just standard ADO. I figured I would end up overriding a method in order to get around the issue but it isn't looking like that is going to matter at this point. You suggestion above would work fine and in this case there isn't so many rows that it will matter much. I was just hoping there would be some magic property or something that would let me set the database in a saveable (or addable) state.
Thanks a bunch.
Tim
>
>http://geek-goddess-bonnie.blogspot.com/2009/09/dataaccess-part-i.html
>http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html
>http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html
>
>~~Bonnie
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform