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.Comm andText = "update_qp" ; //this is the stored procedure which is a simple update statement. there is nothing to it
objCommand.Comm andType = CommandType.Sto redProcedure
objCommand.Para meters.Clear(); //I clear the parameters just in case
objCommand.Para meters.Add("@Qu antity", 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.Upda teCommand = objCommand
objAdapter.Upda te(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.Upda te? 2 2004
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*******@disc ussions.microso ft.com> wrote in message
news:92******** *************** ***********@mic rosoft.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.Comm andText = "update_qp" ; //this is the stored procedure which
is a simple update statement. there is nothing to it. objCommand.Comm andType = CommandType.Sto redProcedure; objCommand.Para meters.Clear(); //I clear the parameters just in case. objCommand.Para meters.Add("@Qu antity", 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.Upda teCommand = objCommand; objAdapter.Upda te(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.Upda te?
Marina
It turned out that objAdapter.Upda te 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*******@disc ussions.microso ft.com> wrote in messag
news:92******** *************** ***********@mic rosoft.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.Comm andText = "update_qp" ; //this is the stored procedure whic
is a simple update statement. there is nothing to it objCommand.Comm andType = CommandType.Sto redProcedure objCommand.Para meters.Clear(); //I clear the parameters just in case objCommand.Para meters.Add("@Qu antity", 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.Upda teCommand = objCommand objAdapter.Upda te(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.Upda te This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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?
1) simply UPDATING the values for all fields in the table, whether or
not any particular field has actually changed
2) running a second SELECT statement and comparing the $_POST vars to
the returned values, and only UPDATING those that have...
|
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 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...
|
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 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...
|
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 one row, all of
them were updated so i immediatelly figured out that i have to include
the id of every entry in the update statement. This is where the
problem is raised. My database is an Access database. The table i am
updating contains a Date...
|
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 utilise the disco file to update the
Corresponding proxy file and reflect the changes made to the web service.
However, the results of doing this with out params is that the results seem
| |
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 executes but it doesn t not update the informations. I ve
tried using TOP 1 and spent hours on this query but i can t get it to
work.
UPDATE table1 SET table1.Name = newName
|
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
changes and merge them into my current Dataset. I've been playing
around with the GetChanges method and Acceptchanges but they just dont
seem to be pulling over the changes and updating my Dataset. Maybe if
someone could give me a sample of...
|
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 if the second select is not null.
If the second select returns null then the updated record should be a.p_cd = 'abc'. But it shows null.
If i use two seperate updates It works fine. But i want to use one update
query:
|
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 finished item. The preview resides within a div and is simply a series of <br>-separated images. Simple html. The system is working fine with FireFox and Safari, but some MSIE 6 and 7 users are reporting that only the first image is updating and the...
|
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...
|
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,...
| |
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...
|
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,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |