473,625 Members | 2,733 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.Acceptc hanges?? Is that not too much (collection to dataset, dataset to database)??
- I cannot use the SQLCommandBuild er because I need joins. What do I have to use if I will update the database???
Thanks in advance.
Nov 16 '05 #1
1 1260
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
1742
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 the best sorting performance? Basically I want to incorporate this into our coding standards. Thanks!
3
4223
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 attributes, all share a base set of 4, one of the question types can have children with <option> elements, this is how the xml looks after serialization.... If you notice there is an extra <SelectionList> around the <option>'s in the final...
1
3169
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 properties (i.e. The ASP:Table control). This is for a menu system. The collections are working when the classes are called directly, but not as a user control. Any advice is appreciated. Code: ------
3
2341
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 Invoice object and then add LineItem objects to the invoice all in memory. How do I get everything to commit to the database in the right order. Invoice invoice = new Invoice(); invoice.OrderDate = DateTime.Now;
7
1144
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 stored procedure into a dataset. next in the code it iterates row by row instantiating a new user object and adding it to a collection? why would you do this when you can work directly with the dataset? i'm very new to this just trying to understand...
3
1192
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 the data to disk as a dataset and was wondering if it was an accepted practice to load/add/edit/delete the data in the dataset from methods within the collections/classes or should I just use them as a container, managing all dataset transactions...
0
1179
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 _ , Form1.tabPage1.Controls _ , Form2.TabPage2.Controls _ } For Each ctl As Control _ In ctlarray
4
1755
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 custom collections, which are serializable, and I want, sometime, to use my custom collection, not IBindingList. Thank in advance
3
1937
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 objects that I can iterate through relatively easily. I've included code at the bottom of this message. I can pretty easily iterate through my employee objects like so: Dim theEmployees As Employees = New Employees
0
8189
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6116
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1499
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.