Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataRow.BeginEdit, EndEdit, and AcceptChanges methods
Message
De
02/02/2005 16:41:34
 
 
À
02/02/2005 13:53:38
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 1.1
Database:
MS SQL Server
Divers
Thread ID:
00982570
Message ID:
00983235
Vues:
27
Well, that's certainly thinking outside the box ... not sure if I would have ever thought of that solution. But, hey, whatever works!!! =)

~~Bonnie


>The text file is just a flat text file, not even delimited, so I need to count characters to parse through each line.
>
>I could read through the whole file and load it into some kind of array, but since my result set is already pretty big, and this will just be running on a standard workstation, it would tax the ram. (Search the text file for each database record would be really inefficient.)
>
>I need to track records that occur in either the database or the textfile, but not the other. If I go through the datatable and check the text file, I would still need to track the textfile records I looked at, so if there were any I didn't examine, I could add them to the database. If I did load the textfile into a simple array, it could be an array of constructs and I could just add another bool field to flag if the record was examined. This would avoid all my problems with DataRows.
>
>I have already settled on a solution, though, that I am happy with. I declare a simple boolean array. The PK for my datatable is a 5-digit U.S. zipcode. I declare a bool array dimensioned at 100000 and just index into it using the int value of the zipcode.
>
>An array of bits doesn't require much memory. I got this working yesterday. I guess it isn't a solution for the "OOP Hall of Fame" but it performs well.
>
>If it wasn't working right now and I had it to do all over again, I think I would take your suggestion. It would take more RAM and slow things down a bit, but the code would be a lot more readable, object-oriented, and easier to maintain. RAM usage and speed isn't critical, because it is a maintenance process, run monthly, to update a zipcode table.
>
>Thanks for helping me think through this. Next time…
>
>>I assume that you go through the textfile and find the matching row in your datatable? Would it be possible to do this in reverse (go through your datatable and see if there's matching in the text file)? This way, you can flag the unchecked rows rather than flag the checked rows (and it won't matter that they are marked as modified, since you have to update the unchecked rows anyway with an inactive status). That way, your checked rows will only be modified if you have to make changes to them.
>>
>>~~Bonnie
>>
>>
>>
>>>The rows fall into four categories: in the textfile, not in the database (addition), in the textfile same as database (verification), in the textfile different from the database (update), and not in the textfile, in the database (deactivation).
>>>
>>>I change a flag in unchecked records to indicate it is no longer inactive.
>>>
>>>The 95% my records are verified, 4% are updated, 1% are added, and the number of deactivations is very rare (less than 1%) but I need to catch them. I would rather only update the 5% of my data table that requires it, not the entire 100%.
>>>
>>>Thanks for thinking about this.
>>>
>>>>David,
>>>>
>>>>And what are you doing with the rows that have not been checked?
>>>>
>>>>~~Bonnie
>>>>
>>>>
>>>>
>>>>>I want to retrieve data from a database, compare it data in a text file, update the data table to match the text file, and keep track of which records in the database were not checked because they weren't listed in the text file.
>>>>>
>>>>>I added a column to my datatable called "IsChecked" that holds a boolean value initialized to false. As I examine each row, I set IsChecked = true. Unchecked rows are VERY rare.
>>>>>
>>>>>Only a small number of rows actually differ from the data in my text file and I only want to send update statements to the database for rows which really require updates.
>>>>>
>>>>>My problem is that setting IsChecked = true sets the RowState value for the row to Modified even if though the other columns don't get changed, so that when I save, an update statement for every row is sent back to the DB.
>>>>>
>>>>>I couldn't find a way to use BeginEdit, EndEdit, and AcceptChanges to make it work. Deleting the IsChecked column didn't help, either.
>>>>>
>>>>>Am I just misusing my DataTable by using it to store information that doesn't exist in my database? Should I track which rows have been read in a separate data structure?
>>>>>
>>>>>If anyone can recommend an online resource that will help me understand how to use this IsChecked column without DataRows thinking that they have really been changed, I would appreciate it.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform