473,763 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

updating muliple records

I'm creating a table that contains multiple records pulled out of the
database. I'm building the table myself and passing it to the page since the
table needs to be fairly customized (ie, a datagrid isn't going to work).

On this page, people can update a variet of records. On submit, I want to
then go in and update all of the records.

Normally, I'd make each form element include a runat: server and then
declare it in my codebhind so I can grab it. However, since I'm building
these forms dynamically, I'm not so sure how to proceed. Can I access a form
element without having to declare it in my code behind? Are there
alternatives? Can I dynamically declare form tags as they're written?

-Darrel
Nov 18 '05 #1
4 2023
Hi Darrel,

I currently implement something that is very much like what you describe.
I'm especially interested in seeing other answers you get to your question
because while my solution works, I'd like something a bit simpler if
possible (but that still gives me all the flexibility I need). I did a bunch
of research on this topic about 8 months ago and got nothing useful in
response - so I rolled my own and here is what I came up with (note: it
works)

1. When the page is requested I retrieve values from db/sp (into either a
DataTable - avoiding DataReaders but that would work as well).

2. Loop through the DataTable - building the output (mostly placing data
into TextBoxes, DDLs, Labels, Literals, or concatenating into a string
variable that contains raw HTML syntax - depending on what's going on in
the page)... then send the page to the user.

At this point the user is viewing the page - makes changes - then clicks a
button to post the page back.

3. Read the FORM collection to determine what is going on in the UI (to
retrieve the values from each of the user-editable controls populated
earlier).

4. Retrieve the values from the database (same stored procedure used to
populate the page in Step 1).

5. Compare values from the Form collection with values in the database - and
make any inserts/updates/deletes that may be required based on the
differences (don't need to update the db when nothing is different). This
step is necessary because the FORM collection contains only the current
values and not before/after values. So, you need some way to know what was
changed. Comparing current values from the FORM collection against the same
data used to populate the controls will give you the opportunity to discover
the changes the user has made. Anyone who has been around the programming
block more than once will see a huge risk in the assumption going on here -
but please read the rest of my post before having a heart attack at this
point.

That's pretty much it. Read the values from the FORM collection during
Postback processing. (this answers your specific question: Can I access a
form element without having to declare it in my code behind?).

For some applications, the sequence I described would lead to potentially
major data integrity problems given the assumption that the values as stored
in the database have not been modified between steps 1 and 4. A bunch of
time could pass between those steps - and the more time that passes there is
a decreased likelihood that the assumption is valid. Of course if that is of
concern, then the basic angorithm could be modified so that the data that is
retrieved in step 1 gets stored into the Session (or ViewState if that would
be a better tradeoff) and then the logic in step 5 compares the users values
(as retrieved from the FORM collection) against those stored in the Session
(or ViewState) to determine what was changed... Then from that, compare
against what's currently in the db and do any updates. Having the values
from step 1 hanging around would let you compare those against the data
store to see if any other users have made any changes to the db since you
read the db in step 1 - and then if any such concurrency issues are
discovered you could take any action necessary - thereby maintaining data
integrity in the face of multi user concurrency concerns. In any case, you
have to be very careful about how this all hangs together: because of the
reliance on the Form collection, there can potentially become a reliance on
the sequence in which values are retrieved from the db. This reliance is
definitely a problem where multi-user concurrency is of concern. Not only
can another user update an existing row, but can insert or remove rows -
thereby causing your logic - unless you are very careful - to think that
every value the user could change (in the FORM collection) was changed, when
in fact none were changed... you get the idea.

Good Luck!

GH

"Darrel" <no*****@nospam .com> wrote in message
news:ef******** ******@TK2MSFTN GP14.phx.gbl...
I'm creating a table that contains multiple records pulled out of the
database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a datagrid isn't going to work).

On this page, people can update a variet of records. On submit, I want to
then go in and update all of the records.

Normally, I'd make each form element include a runat: server and then
declare it in my codebhind so I can grab it. However, since I'm building
these forms dynamically, I'm not so sure how to proceed. Can I access a form element without having to declare it in my code behind? Are there
alternatives? Can I dynamically declare form tags as they're written?

-Darrel

Nov 18 '05 #2
> That's pretty much it. Read the values from the FORM collection during
Postback processing. (this answers your specific question: Can I access a
form element without having to declare it in my code behind?).


Ah! Yes, that's the answer! Simple enough.

After reading the rest of your solution, I guess I'd say that I'm thinking
the exact same thing.

The one question I had is what, if any, benefit there is to comparing the
records to ensure a change vs. just updating them all anyways (regardless of
a change)?

I suppose the argument is that if I've already loaded the values the first
time, then they're already there for comparison. The catch is that I'm doing
a recursive request to the db, so I can't just look at one ds. I suppose I
could add each record into a second ds, and use that for comparison. Hmm...

Well, at this point, I guess I do see the value in the comparison first.
However, as I'll never have more than 30 or so records, I don't think it's a
huge deal.

I do note the the issue with the time since data load vs. data submit. In
this case, the page iin question will be updated rarely, and, when so,
probably by only one person, so It's not a huge concern in this particular
case. However, I do see it being an issue down the road for larger systems.
I'll have to take that into consideration.

-Darrel
Nov 18 '05 #3
<<The one question I had is what, if any, benefit there is to comparing the
records to ensure a change vs. just updating them all anyways (regardless of
a change)?>>

One reason to do the comparison is because in some cases I've discovered
that the FORM collection will omit a control (e.g., textbox that is not
checked). So, we have to know what it means to have a control not included
in the FORM collection. In my case I'm not simply changing the value of
existing db rows based on user action. I'm also inserting or removing rows
from the underlying db when some checkboxes are checked. So, I can't have a
simple rule that states "always update all rows all the time and save myself
the headache of figuring when to do an update". My equivalent rule that
wouldn't work would have to be something like "always insert a row when the
checkbox exists and always delete the row when the checkbox does not exist
in the FORM collection." On the face it appears to be a reasonable rule -
but what about when a row already exists and the user does not uncheck the
box. In that case the rule would get me into trouble by inserting a second
row (or actually the insert would choke because of a primary key
constraint...). In any case the *meaning of* either the presence or absence
of a checkbox in the FORM collection is by itself ambiguous. To know the
meaning I have to know what the values were originally - thus the need to
compare before post-back and after post-back values (and the FORM doesn't
contain the before post-back info).

Separately - when it's time to save changes to the db during postback - you
might consider using a couple of arrays that contain the results of any
comparisons - and then in a couple of loops execute one or more stored
procedures to perform the db updates (yes - one execution per
insert/update/delete). You can wrap all these updates in a transaction if
necessary. Doing this might offer faster performance than manipulating your
data in a DataSet and, more importantly, might give you more control over pr
ocessing sequences. This is more of a personal thing though...I still have
nightmares from the classic ADO UpdateBatch() command... ADO.NET is very
different with respect to batch updating so you might be just as well off
with having it wrap all that logic for you...

GH
"Darrel" <no*****@nospam .com> wrote in message
news:eD******** ******@TK2MSFTN GP12.phx.gbl...
That's pretty much it. Read the values from the FORM collection during
Postback processing. (this answers your specific question: Can I access a form element without having to declare it in my code behind?).
Ah! Yes, that's the answer! Simple enough.

After reading the rest of your solution, I guess I'd say that I'm thinking
the exact same thing.

The one question I had is what, if any, benefit there is to comparing the
records to ensure a change vs. just updating them all anyways (regardless

of a change)?

I suppose the argument is that if I've already loaded the values the first
time, then they're already there for comparison. The catch is that I'm doing a recursive request to the db, so I can't just look at one ds. I suppose I
could add each record into a second ds, and use that for comparison. Hmm...
Well, at this point, I guess I do see the value in the comparison first.
However, as I'll never have more than 30 or so records, I don't think it's a huge deal.

I do note the the issue with the time since data load vs. data submit. In
this case, the page iin question will be updated rarely, and, when so,
probably by only one person, so It's not a huge concern in this particular
case. However, I do see it being an issue down the road for larger systems. I'll have to take that into consideration.

-Darrel

Nov 18 '05 #4
Guadala:

I'm late getting back to you but did want to say that I really appreciate
the explanation. Thanks!

-Darrel

"Guadala Harry" <GM**@NoSpam.co m> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
<<The one question I had is what, if any, benefit there is to comparing
the
records to ensure a change vs. just updating them all anyways (regardless
of
a change)?>>

One reason to do the comparison is because in some cases I've discovered
that the FORM collection will omit a control (e.g., textbox that is not
checked). So, we have to know what it means to have a control not included
in the FORM collection. In my case I'm not simply changing the value of
existing db rows based on user action. I'm also inserting or removing rows
from the underlying db when some checkboxes are checked. So, I can't have
a
simple rule that states "always update all rows all the time and save
myself
the headache of figuring when to do an update". My equivalent rule that
wouldn't work would have to be something like "always insert a row when
the
checkbox exists and always delete the row when the checkbox does not exist
in the FORM collection." On the face it appears to be a reasonable rule -
but what about when a row already exists and the user does not uncheck the
box. In that case the rule would get me into trouble by inserting a second
row (or actually the insert would choke because of a primary key
constraint...). In any case the *meaning of* either the presence or
absence
of a checkbox in the FORM collection is by itself ambiguous. To know the
meaning I have to know what the values were originally - thus the need to
compare before post-back and after post-back values (and the FORM doesn't
contain the before post-back info).

Separately - when it's time to save changes to the db during postback -
you
might consider using a couple of arrays that contain the results of any
comparisons - and then in a couple of loops execute one or more stored
procedures to perform the db updates (yes - one execution per
insert/update/delete). You can wrap all these updates in a transaction if
necessary. Doing this might offer faster performance than manipulating
your
data in a DataSet and, more importantly, might give you more control over
pr
ocessing sequences. This is more of a personal thing though...I still have
nightmares from the classic ADO UpdateBatch() command... ADO.NET is very
different with respect to batch updating so you might be just as well off
with having it wrap all that logic for you...

GH
"Darrel" <no*****@nospam .com> wrote in message
news:eD******** ******@TK2MSFTN GP12.phx.gbl...
> That's pretty much it. Read the values from the FORM collection during
> Postback processing. (this answers your specific question: Can I access a > form element without having to declare it in my code behind?).


Ah! Yes, that's the answer! Simple enough.

After reading the rest of your solution, I guess I'd say that I'm
thinking
the exact same thing.

The one question I had is what, if any, benefit there is to comparing the
records to ensure a change vs. just updating them all anyways (regardless

of
a change)?

I suppose the argument is that if I've already loaded the values the
first
time, then they're already there for comparison. The catch is that I'm

doing
a recursive request to the db, so I can't just look at one ds. I suppose
I
could add each record into a second ds, and use that for comparison.

Hmm...

Well, at this point, I guess I do see the value in the comparison first.
However, as I'll never have more than 30 or so records, I don't think
it's

a
huge deal.

I do note the the issue with the time since data load vs. data submit. In
this case, the page iin question will be updated rarely, and, when so,
probably by only one person, so It's not a huge concern in this
particular
case. However, I do see it being an issue down the road for larger

systems.
I'll have to take that into consideration.

-Darrel


Nov 18 '05 #5

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

Similar topics

6
5769
by: Hennie de Nooijer | last post by:
Hi, Currently we're a building a metadatadriven datawarehouse in SQL Server 2000. We're investigating the possibility of the updating tables with enormeous number of updates and insert and the use of checkpoints (for simple recovery and Backup Log for full recovery). On several website people speak about full transaction log and the pace of growing can't keep up with the update. Therefore we want to create a script which flushes the...
0
1556
by: Luke Airig | last post by:
I am using the Saxon engine and I have an xml file that contains batches of records. Each batch starts with a header record and the associated detail records immediately follow each header. There can be multiple batches in a single file, each batch indicated by a new header. I need to create a tab-delimited output file that appends all of the header record fields in front of each associated detail record within the same batch. The...
1
1867
by: Chris Jackson | last post by:
I'm a novice Access user and am not sure how to solve the following problem. Any help with the following would be greatly appreciated! I have two tables with identical structures, the first holds the data input for a questionnaire, the second holds the scores from the questionnaire, to move the scores I've set up 2 action queries, the first appends the record to the second table, the second action query 'updates' the results by...
1
2034
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass the applicable fields in the gridview to a sqldatasource which in turn calls a sproc with the appropriate parameters and data. Any ideas? Thanks in advance,
1
1507
by: davidgordon | last post by:
Hi, If I am updating a list of records for a user on an asp page, is there a way to hold the page updating, even if they refresh the page, until I have updated all the records. i.e. rather than them seeing records change 1 at a time if they refreshed their page, all the records would update together in 1 go, a bit like a batch update ?
5
1524
by: serge | last post by:
Is it generally or almost always better to have multiple small SPs and functions to return a result set instead of using a single big 1000+ lines SP? I have one SP for example that is 1000+ lines and early analysis of the SP I see it first has 3 big blocks of code separated by IF statements. Then within each IF block of code I see 3-4 UNIONs. UNIONs that means they are all returning the same columns so I am guessing these are prime...
34
10844
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have VBA code that wrote the results of that away to the db, either creating new records or updating existing records, whichever was relevant. This may also include deleting records. Now I generally do this by opening a recordset on the source data...
10
2239
by: chimambo | last post by:
Hi All, I have a little problem. I am retrieving records from a table and I want to update the records using checkboxes. I am able to display the database record quite alright and I have created an array of checkboxes, but my update loop is not working. Here is my code: /*---------This retrieves the records -------------*/ if($row_md) { do{ echo "<tr><td text align='right'>";
5
2911
by: Bill Schanks | last post by:
I have a winform app (VB 2005) that allows users to export data to excel, make updates to the excel file and import the data from that Excel file and update the database. My question is: Is it best to do it this way, calling the update stored procedure for every update? Or should I be loading this data into a staging table, and if all goes well do the 'Real' Update. Or put this into a data adapter and update from that? The application...
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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
10145
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8822
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
7366
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
5270
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
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
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.