Hi posting again because no answer to previous..
tring to loop through a recordset and update a record, thing is it
only updates the first record in the table rather than searching
through the entire table or records returned, and updating a record if
certain criteria is met.
shouldn't the while loop do this?
I know my syntax must be wrong, but difficult to work out how or where
table = String(Request. Cookies("table" ));
var rsproducts = Server.CreateOb ject("ADODB.Rec ordset");
rsproducts.Acti veConnection = conn_STRING;
rsproducts.Sour ce = "SELECT * FROM "+ table +" WHERE
ProductID='"+Pr oductID+"'";
rsproducts.Curs orType = 3;
rsproducts.Curs orLocation = 2;
rsproducts.Lock Type = 1;
rsproducts.Open ();
var rsproducts_numR ows = 0;
//problem here//
while(!rsproduc ts.EOF){
if (String(rsprodu cts.Fields.Item ("size").Val ue) == size &&
String(rsproduc ts.Fields.Item( "colour").Value ) == colour ){//if size
and colour are the same as what's in the results...
conn = Server.CreateOb ject('ADODB.Com mand');
conn.ActiveConn ection = conn_STRING;
conn.CommandTex t = ("UPDATE "+ table + " SET Quantity = Quantity
+'"+Quantity+ "' WHERE ProductID='"+Pr oductID+"'AND size='"+size+"' AND
colour='"+colou r+"'" ); ////then only update the quantity//
conn.Execute();
conn.ActiveConn ection.Close();
Response.Redire ct("../index.asp");
}else{// if item does not match with others then insert new record
//create sql insert
var sql = "INSERT INTO "+ table +
"(ProductID,Pro ductName,Price, Quantity,";
sql = sql+ "size,colour,Pr oductCode,NavID ,groupfield)";
sql = sql+" VALUES ('"+ProductID+" ','"+ProductNam e+"','"+Price+" ','"+Quantity+" ','"+size+"'";
sql = sql+ ",'"+colour+"', '"+ProductCode+ "','"+NavID+"', '1')";
conn = Server.CreateOb ject('ADODB.Com mand');//make the sql connection
object and open it here
conn.ActiveConn ection = conn_STRING;//connect
conn.CommandTex t = (sql);
conn.Execute();//do the job
conn.ActiveConn ection.Close();//close
Response.Redire ct("../index.asp");
}
rsproducts.Move Next();
}
as i said before this works but only for the first record in the table
why isn't it looping through? 4 4077
Because you are redirecting after the first row is evaluated and updated or
inserted.
Bob Lehmann
"Roy Adams" <ro*******@ntlw orld.com> wrote in message
news:13******** *************** ***@posting.goo gle.com... Hi posting again because no answer to previous.. tring to loop through a recordset and update a record, thing is it only updates the first record in the table rather than searching through the entire table or records returned, and updating a record if certain criteria is met. shouldn't the while loop do this? I know my syntax must be wrong, but difficult to work out how or where
table = String(Request. Cookies("table" ));
var rsproducts = Server.CreateOb ject("ADODB.Rec ordset"); rsproducts.Acti veConnection = conn_STRING; rsproducts.Sour ce = "SELECT * FROM "+ table +" WHERE ProductID='"+Pr oductID+"'"; rsproducts.Curs orType = 3; rsproducts.Curs orLocation = 2; rsproducts.Lock Type = 1; rsproducts.Open (); var rsproducts_numR ows = 0;
//problem here// while(!rsproduc ts.EOF){ if (String(rsprodu cts.Fields.Item ("size").Val ue) == size && String(rsproduc ts.Fields.Item( "colour").Value ) == colour ){//if size and colour are the same as what's in the results...
conn = Server.CreateOb ject('ADODB.Com mand'); conn.ActiveConn ection = conn_STRING; conn.CommandTex t = ("UPDATE "+ table + " SET Quantity = Quantity +'"+Quantity+ "' WHERE ProductID='"+Pr oductID+"'AND size='"+size+"' AND colour='"+colou r+"'" ); ////then only update the quantity// conn.Execute(); conn.ActiveConn ection.Close(); Response.Redire ct("../index.asp");
}else{// if item does not match with others then insert new record
//create sql insert var sql = "INSERT INTO "+ table + "(ProductID,Pro ductName,Price, Quantity,"; sql = sql+ "size,colour,Pr oductCode,NavID ,groupfield)"; sql = sql+" VALUES
('"+ProductID+" ','"+ProductNam e+"','"+Price+" ','"+Quantity+" ','"+size+"'"; sql = sql+ ",'"+colour+"', '"+ProductCode+ "','"+NavID+"', '1')";
conn = Server.CreateOb ject('ADODB.Com mand');//make the sql connection object and open it here conn.ActiveConn ection = conn_STRING;//connect conn.CommandTex t = (sql); conn.Execute();//do the job conn.ActiveConn ection.Close();//close Response.Redire ct("../index.asp"); } rsproducts.Move Next(); }
as i said before this works but only for the first record in the table why isn't it looping through?
If this is a SQL Server database, you can do this in a stored procedure and
get rid of this messy loop. I'll assume you have a little bit of interest
in using a SINGLE table instead of using a table for each user.
CREATE PROCEDURE dbo.updateCart
@sessionID INT,
@productID VARCHAR(32),
@size VARCHAR(2),
@colour VARCHAR(12),
@quantity INT
AS
BEGIN
SET NOCOUNT ON
UPDATE CartTable
SET Quantity = @quantity
WHERE
SessionID = @sessionID
AND productID = @productID
AND size = @size
AND colour = @colour
IF @@ROWCOUNT = 0
INSERT CartTable -- I'll let you fill in the rest...
END
GO
-- http://www.aspfaq.com/
(Reverse address to reply.)
"Roy Adams" <ro*******@ntlw orld.com> wrote in message
news:13******** *************** ***@posting.goo gle.com... Hi posting again because no answer to previous.. tring to loop through a recordset and update a record, thing is it only updates the first record in the table rather than searching through the entire table or records returned, and updating a record if certain criteria is met. shouldn't the while loop do this? I know my syntax must be wrong, but difficult to work out how or where
table = String(Request. Cookies("table" ));
var rsproducts = Server.CreateOb ject("ADODB.Rec ordset"); rsproducts.Acti veConnection = conn_STRING; rsproducts.Sour ce = "SELECT * FROM "+ table +" WHERE ProductID='"+Pr oductID+"'"; rsproducts.Curs orType = 3; rsproducts.Curs orLocation = 2; rsproducts.Lock Type = 1; rsproducts.Open (); var rsproducts_numR ows = 0;
//problem here// while(!rsproduc ts.EOF){ if (String(rsprodu cts.Fields.Item ("size").Val ue) == size && String(rsproduc ts.Fields.Item( "colour").Value ) == colour ){//if size and colour are the same as what's in the results...
conn = Server.CreateOb ject('ADODB.Com mand'); conn.ActiveConn ection = conn_STRING; conn.CommandTex t = ("UPDATE "+ table + " SET Quantity = Quantity +'"+Quantity+ "' WHERE ProductID='"+Pr oductID+"'AND size='"+size+"' AND colour='"+colou r+"'" ); ////then only update the quantity// conn.Execute(); conn.ActiveConn ection.Close(); Response.Redire ct("../index.asp");
}else{// if item does not match with others then insert new record
//create sql insert var sql = "INSERT INTO "+ table + "(ProductID,Pro ductName,Price, Quantity,"; sql = sql+ "size,colour,Pr oductCode,NavID ,groupfield)"; sql = sql+" VALUES
('"+ProductID+" ','"+ProductNam e+"','"+Price+" ','"+Quantity+" ','"+size+"'"; sql = sql+ ",'"+colour+"', '"+ProductCode+ "','"+NavID+"', '1')";
conn = Server.CreateOb ject('ADODB.Com mand');//make the sql connection object and open it here conn.ActiveConn ection = conn_STRING;//connect conn.CommandTex t = (sql); conn.Execute();//do the job conn.ActiveConn ection.Close();//close Response.Redire ct("../index.asp"); } rsproducts.Move Next(); }
as i said before this works but only for the first record in the table why isn't it looping through?
There are some significant diferences between this code and your previous
post. I responded to theother under the assumption that ProductID was
significant enough to find a single item, it wasn't obvious that color and
size needed to accompany it.
While I still believe stored procdure would be best, Aaron covered this in
dpth enough that I don't feel the need to get into it.
The easiest wayto overcome your curent problem with minimal changes would be
to simply add AND size='"+size+"' AND
colour='"+colou r+"'" to your SELECT statement.
Please also double check your field types, because in your previous post
things like PRoductID were numeric and you have now changed them to strings.
-T
Thank's Tarwn
you were right i took out the while loop and changed the select
statement works a treat thank's again
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: PG |
last post by:
When deleting a row from the database, that id is now missing.
So what I'm trying to do is update in a loop (maybe an sql loop if
there is one) of all of the id numbers - sort of like renaming them.
It did partly work because all the id's were set to 22. Thats because
there was 22 rows.
Here's the code I used:
$result = mysql_query ("SELECT * FROM counter");
for($counting = 1; $row = mysql_fetch_row ($result); ++$counting)
|
by: Dave |
last post by:
I have to automate a process that assigns sales leads to sales people.
For example:
Every day we buy a list of sales leads, it ranges in size from 50 -
100 records.
We have a team of sales people that also can range from 5 - 8 people.
I need to take the new records and divide them evenly among the sales
people.
|
by: RC |
last post by:
I have a table that lists many box numbers. Each box number has a
Pallet Number (indicating which pallet the box is in). When the
Pallets are loaded into a shipping Container I need to update the
table to indicate which pallets and boxes are in the container.
In my code below, in the table named "Products", I find the first
Pallet Number that matches the Pallet Number typed in the box on my
form (PalletNumberContainerFormComboBox)....
|
by: RC |
last post by:
My code below will loop through all the records in the table, and when
the if statement is true it goes to the
***Me.ContainerNumberProductsTable = GETContainerNumber.Value*** bit
like should but it does not make the change/update in the table. Any
ideas?
Dim rst As Object
Set rst = Me.Recordset.Clone
If Not rst.EOF Then Me.Bookmark = rst.Bookmark
|
by: David |
last post by:
Hi,
I have a continuous form based on a query.
Lets say the form displays 6 records.
I also have a button against each record which sets a field to Y or N
for each record.
I am trying to copy partial fields only for those records where the
field = Y
| |
by: ozgirl via AccessMonster.com |
last post by:
Hi,
hopeing someone can help me here...
I have a deductions table and form and want to be able to add many deductions
to the table by having only a few fields on the form
form fields: deduction ID, start date, end date and amount
what i want to be able to do is keep adding a deduction each 7 days from the
|
by: Stewart Graefner |
last post by:
Here is a chunk of code that works for an individual record. It
evaluates dates and checks or unchecks boxes as it goes along. It may
not be pretty but it works. What my problem is that I need it to
evaluate all the records(200+) in my db and change those which need
changing. Having to do it individually would defeat the purpose of
developing this code. What I would like to be able to do is either 1.
Open the db push a button and all the...
|
by: Dacuna |
last post by:
Is it possible to use a recursive function to loop through a recordset faster?
I have a table that I need to edit its contents after doing some calculation. The table has one field has an RawData field and a CalcData field. I open the recordset, exctract the RawData and after doing some calculations update the CalcData with the calculated data. In code I have something as follows.
dim rs as new ADODB.Recordset
dim cmdUpdate as new...
|
by: DWolff |
last post by:
My application is to re-assign leads to different groups of salespeople by sequentially assigning them to each salesperson. I've got an Access 2000 front end to an MS-SQL database.
Currently, I do this effectively (but sloppily and slowly) by exporting Access records to Excel, doing my assignments there, importing back into a new work table in Access, and running an update query (joining on Lead.ID). However, I'm soon going to exceed 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: 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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |