473,322 Members | 1,778 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,322 software developers and data experts.

Updating the first row only?

The flow of my app is as follows
1) Pull up an order and change the quantity of a textbox item. (Ex: change the quantity from 1 to 2
2) Click on the Update button
3) When the page posts back you should see the updated quantity of the item. (by the way, in some cases there will be multiple lines for an order...this is where the problem comes in.

What happens is that the process works...for the first row of data only. I need the app to update all lines of an order, not just the first line. Below is the problematic code

//Code Star
for(int counter = 0; counter < tbl.Rows.Count; counter++) //I have verified that the count of table rows is correct, no matter the amount...so the issue is not with the row coun

objCommand.CommandText = "update_qp"; //this is the stored procedure which is a simple update statement. there is nothing to it
objCommand.CommandType = CommandType.StoredProcedure
objCommand.Parameters.Clear(); //I clear the parameters just in case
objCommand.Parameters.Add("@Quantity", tbl.Rows[counter]["Quantity"]); //if you set the counter variable to 1 it will update the second order line correctly, if you set the counter variable to 2 it will update the third order line correctly, etc. this is good because it shows that the data is there and it is correct. However, by default (i.e. leave it set to tbl.Rows[counter]) it will only display the first row (i.e. tbl.Rows[0]) , even though this code is contained within a looping structure
objAdapter.UpdateCommand = objCommand
objAdapter.Update(tbl)

//Code En

Does anyone know what is going on? The data is all there, it recognizes how many rows the table has, and it updates perfectly if you hardcode the row numbers. So why won't this work by looping through? Does it have something to do with the objAdapter.Update?
Nov 16 '05 #1
2 1987
I'm confused - you are setting a stored procedure on a SqlCommand object -
but then using a data adapter to do the updating?

When you call Update on the data adapter, it does the update on ALL the rows
in the entire table. After that, it calls AcceptChanges, which resets the
state of all the rows to unchanged. Any other Updates you call after this
in your loop, won't do anything - as all the rows are marked as unchanged,
hence, there is nothing to update. So if you command is data adapter's
update command is objCommand, then, the update will happen once - with the
value at row 0 being used for all the rows in the table.

"George" <an*******@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
The flow of my app is as follows:
1) Pull up an order and change the quantity of a textbox item. (Ex: change the quantity from 1 to 2) 2) Click on the Update button.
3) When the page posts back you should see the updated quantity of the item. (by the way, in some cases there will be multiple lines for an
order...this is where the problem comes in.)
What happens is that the process works...for the first row of data only. I need the app to update all lines of an order, not just the first line. Below
is the problematic code.
//Code Start
for(int counter = 0; counter < tbl.Rows.Count; counter++) //I have verified that the count of table rows is correct, no matter the amount...so
the issue is not with the row count {
objCommand.CommandText = "update_qp"; //this is the stored procedure which is a simple update statement. there is nothing to it. objCommand.CommandType = CommandType.StoredProcedure;
objCommand.Parameters.Clear(); //I clear the parameters just in case.
objCommand.Parameters.Add("@Quantity", tbl.Rows[counter]["Quantity"]); //if you set the counter variable to 1 it will update the second order line
correctly, if you set the counter variable to 2 it will update the third
order line correctly, etc. this is good because it shows that the data is
there and it is correct. However, by default (i.e. leave it set to
tbl.Rows[counter]) it will only display the first row (i.e. tbl.Rows[0]) ,
even though this code is contained within a looping structure. objAdapter.UpdateCommand = objCommand;
objAdapter.Update(tbl);
}
//Code End

Does anyone know what is going on? The data is all there, it recognizes

how many rows the table has, and it updates perfectly if you hardcode the
row numbers. So why won't this work by looping through? Does it have
something to do with the objAdapter.Update?
Nov 16 '05 #2
Marina

It turned out that objAdapter.Update was indeed the problem. It should have been objAdapter.Fill. Now it works perfectly

----- Marina wrote: ----

I'm confused - you are setting a stored procedure on a SqlCommand object
but then using a data adapter to do the updating

When you call Update on the data adapter, it does the update on ALL the row
in the entire table. After that, it calls AcceptChanges, which resets th
state of all the rows to unchanged. Any other Updates you call after thi
in your loop, won't do anything - as all the rows are marked as unchanged
hence, there is nothing to update. So if you command is data adapter'
update command is objCommand, then, the update will happen once - with th
value at row 0 being used for all the rows in the table

"George" <an*******@discussions.microsoft.com> wrote in messag
news:92**********************************@microsof t.com..
The flow of my app is as follows
1) Pull up an order and change the quantity of a textbox item. (Ex: chang the quantity from 1 to 2 2) Click on the Update button
3) When the page posts back you should see the updated quantity of th item. (by the way, in some cases there will be multiple lines for a
order...this is where the problem comes in.
What happens is that the process works...for the first row of data only. need the app to update all lines of an order, not just the first line. Belo
is the problematic code //Code Star

for(int counter = 0; counter < tbl.Rows.Count; counter++) //I hav

verified that the count of table rows is correct, no matter the amount...s
the issue is not with the row coun
objCommand.CommandText = "update_qp"; //this is the stored procedure whic is a simple update statement. there is nothing to it objCommand.CommandType = CommandType.StoredProcedure
objCommand.Parameters.Clear(); //I clear the parameters just in case
objCommand.Parameters.Add("@Quantity", tbl.Rows[counter]["Quantity"]) //if you set the counter variable to 1 it will update the second order lin
correctly, if you set the counter variable to 2 it will update the thir
order line correctly, etc. this is good because it shows that the data i
there and it is correct. However, by default (i.e. leave it set t
tbl.Rows[counter]) it will only display the first row (i.e. tbl.Rows[0])
even though this code is contained within a looping structure objAdapter.UpdateCommand = objCommand
objAdapter.Update(tbl)

//Code En
Does anyone know what is going on? The data is all there, it recognize

how many rows the table has, and it updates perfectly if you hardcode th
row numbers. So why won't this work by looping through? Does it hav
something to do with the objAdapter.Update

Nov 16 '05 #3

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

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
2
by: George | last post by:
The flow of my app is as follows 1) Pull up an order and change the quantity of a textbox item. (Ex: change the quantity from 1 to 2 2) Click on the Update button 3) When the page posts back you...
4
by: Darrel | last post by:
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...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
6
by: recif20002002 | last post by:
Hello I am trying to update table1 and set a new value with a condition selecting only the results for the element with the specified ID and the first one with the Date field null. The query...
6
by: mike11d11 | last post by:
I'm trying to create an application that will have multiple users working off a table on a SQL server. Since multi users will be updating different records at any given moment, how can i get those...
6
by: Hevan | last post by:
Hi, I am using this sql for updating a large table. This sql should update a record like 'abc123'. The first select will return 'abc' and the second select will return '123'. This works fine...
5
by: rosaryshop | last post by:
I'm working a jewelry/rosary design web site at http://www.rosaryshop.com/rosariesAndKits2.php. As the user makes selections, it updates images of various parts, giving them a preview of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.