473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Design question

Hello,
VB6. I have a class. The class receives a bunch of individual items from
an asp page, then updates the database. My question is what is the best way
you have found to update the database, one record at a time -or- send every
that needs to get written to the database to the class, then execute a
function to update the tables.
Here are the two scenarios.
-1-
For each record I need to insert into the db, Call a method on a class,
passing the items. In the method, execute an insert statement.

-or-
-2-
Have a method, like 'additem'. This method would add the stuff to a
collection in the class. Then, when the asp page is finished adding all its
items, call a method to take each item in the collection and insert it to
the database.

I have done it both ways in the past, but was curious to know the way you
guys do something like this. Thanks for your time.

Jul 17 '05 #1
2 2957
Personally, I am in favour of putting database handling in its own
classes or even a separate layer. It helps you switch databases if you
ever want to, and I usually do want to in my unit tests.
No method is "absolutely correct". You can represent the whole database
structure in an object layer, but in some cases that could be too much
work with no gain.
If you find yourself typing (or pasting) duplicate code, like database
handling code, you can refactor that code into its own class and refer
to an instance of that class.
In general, you can always refactor a working design into a better
designed situation, so don't fix yourself on starting perfectly.

Lots of databases have optimizations, but they can be different. Know
your database. I know MS-Access and SQL server can handle repetative
simple commands well (but in different ways). Especially if you are
writing for different database types, you'd best stick to simple
commands or abstract database commands to specific objects for the
database types.

Best regards

Jack wrote:
Hello,
VB6. I have a class. The class receives a bunch of individual items from
an asp page, then updates the database. My question is what is the best way
you have found to update the database, one record at a time -or- send every
that needs to get written to the database to the class, then execute a
function to update the tables.
Here are the two scenarios.
-1-
For each record I need to insert into the db, Call a method on a class,
passing the items. In the method, execute an insert statement.

-or-
-2-
Have a method, like 'additem'. This method would add the stuff to a
collection in the class. Then, when the asp page is finished adding all its
items, call a method to take each item in the collection and insert it to
the database.

I have done it both ways in the past, but was curious to know the way you
guys do something like this. Thanks for your time.

Jul 17 '05 #2

"Jack" <ja**@jack.net> wrote in message news:H5efe.3199$EC6.3128@trndny06...
Hello,
Here are the two scenarios.
-1-
For each record I need to insert into the db, Call a method on a class,
passing the items. In the method, execute an insert statement.

-or-
-2-
Have a method, like 'additem'. This method would add the stuff to a
collection in the class. Then, when the asp page is finished adding all its
items, call a method to take each item in the collection and insert it to the
database.

I have done it both ways in the past, but was curious to know the way you guys
do something like this. Thanks for your time.


It sounds to me like you end up with one insert statement per item either way.
In scenario 1, you pass one item, and it gets inserted.
In scenario 2, the items you pass are collected, and then each one gets
inserted.

The second approach is more flexible. If you called its AddItem method just
once, and then called its DoInserts method, you would get the result of the
first approach. So setting it up that way lets you have it both ways, and you
can use whichever works best in each situation.

With the second approach, you could also create a procedure in the database that
would accept an array of data and do the multiple inserts directly in the
database.
Jul 17 '05 #3

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

Similar topics

5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
2
by: Test User | last post by:
Hi all, (please excuse the crosspost as I'm trying to reach as many people as possible) I am somewhat familiar with Access 2000, but my latest project has me stumped. So, I defer to you...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
17
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
6
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
19
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
8
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.