473,396 Members | 1,893 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,396 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 1992
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
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...
0
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...
0
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,...

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.