473,499 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

collections directly to database

jac
Hey,
Newbie in using ADO.NET.

What I do now : I read the database with an OleDbDataReader. For each row I read I make an object (let say Person + that object contains a collection with the addresses etc.). All the objects I put in a collection called ‘Persons’.
Then I work on that collection (delete, update, add). Each object in the collection contains a state (Add, Update or deleted state).

At the end I want to go back to the database.
What is a best practice to do this?
- Do I pump my collection ‘Persons’ in a dataset, and for each row I set the datarowstate (= state of each object in my collection). I don’t know if this is possible. And then I do dataset.Update and Dataset.Acceptchanges?? Is that not too much (collection to dataset, dataset to database)??
- I cannot use the SQLCommandBuilder because I need joins. What do I have to use if I will update the database???
Thanks in advance.
Nov 16 '05 #1
1 1254
Hi
A best practice is to use dataset form the outset. The dataset object
record all the changes that is done on a each row on any of it table ( this
is why it keep many stats for the row ) . when you are done you can use the
update method of the data adaptor passing to it as argument your connection
and your dataset . this update method will write all the updates ( that
is in the data set ) back to your database .
The way this is done , as the dataset keep the states of the rows , it
generate the appropriate SQL that would get it from the original state (
when it was first filled ) to the current state ( the state of the dataset
now ) . the good part is that you don't need to worry about all that
however.
One thing I need to mention is that you need to call the update method
on the dataAdaptor BEFORE CALLING ACCEPT CHANGES ON THE DATASET ( as
accept changes delete all info of past states on the dataset ) this method
make the data set throw all past changes and consider the current state as
the original state . so you should call this method only after you did the
update so that the dataset would consider it self as a fresh new one .
I hope this was clear enough , but I think you still need to read a bit
about these methods
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1723
by: Shemp | last post by:
I'm looking for information on what type of collection fits a particular need. For example, what collection provides the best performance for a large volume of records? What collection provides...
3
4202
by: MattB | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different...
1
3157
by: Jay Douglas | last post by:
I need help getting the collections to show up in the property window of a user control. I want to be able to edit the collection items just like any other asp.net control that has collection...
3
2331
by: aa7im | last post by:
I am trying to design a good domain model for a system I am working on but I am having a hard time trying to figure out how to deal with relations and transaction... For example if I create an...
7
1133
by: rodchar | last post by:
hey all, i was checking out time tracker on asp.net one of the starter kit projects. i was wondering why the users datagrid gets loaded the way does. first it pulls all the users in from a...
3
1185
by: Paul | last post by:
Hello, I'm upgrading a small single user app to VB.NET and have a few questions about loading classes & collections classes with the data from a one to many dataset structure. I'm serializing...
0
1171
by: KR | last post by:
I finally got back to this. The syntax that worked for me was: For Each ctlarray As Control.ControlCollection _ In New Control.ControlCollection() _ { Form1.Controls _ ,...
4
1748
by: Giorgio Parmeggiani | last post by:
Hi I am using the svcutil parameter: /ct to obtain IBindingList from WCF Service. I can exclude some collection or some WCF service methods from this conversion? I have some strongly typed...
3
1926
by: Scott Stark | last post by:
Hello, I'm trying to get a better handle on OOP programming principles in VB.NET. Forgive me if this question is sort of basic, but here's what I want to do. I have a collection of Employee...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.