Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

updating multiple records with VBScript and SQL
I have an ASP page that needs to update multiple records.

I have 4 variables that are a string of values, for instance:

id = "1,2,3,4"
name = "Charlie, Lucy, Linus, Snoopy"

so I need to create 4 SQL statements like:
Update table Set name = 'Charlie' where id = '1';
Update table Set name = 'Lucy' where id = '2';

and so on...

I've used the Split command before to separate a list into an array, but
not sure how to deal with multiple arrays like this.


Suggestions?

Thanks, Amanda




*** Sent via Developersdex http://www.examnotes.net ***

Report this thread to moderator Post Follow-up to this message
Old Post
Amanda Hallock
05-26-05 01:55 AM


Re: updating multiple records with VBScript and SQL
In message <eWBMljVYFHA.2508@TK2MSFTNGP15.phx.gbl>, Amanda Hallock
<amanda2@southwind.org> writes
>
>I have an ASP page that needs to update multiple records.
>
>I have 4 variables that are a string of values, for instance:
>
>id = "1,2,3,4"
>name = "Charlie, Lucy, Linus, Snoopy"
>
>so I need to create 4 SQL statements like:
>Update table Set name = 'Charlie' where id = '1';
>Update table Set name = 'Lucy' where id = '2';
>
>and so on...
>
>I've used the Split command before to separate a list into an array, but
>not sure how to deal with multiple arrays like this.

Why not split each string into a separate array and then use both
array's to build your update statement. After all, you can run Split
more than once on a page :-)

Just remember to check the bounds of each array so that you don't try
updating 5 records when there is only data for 4.

--
Andrew D. Newbould                  E-Mail:  newsgroups@NOSPAMzadsoft.com

ZAD Software Systems                Web   :  www.zadsoft.com

Report this thread to moderator Post Follow-up to this message
Old Post
Andrew D. Newbould
05-26-05 01:55 AM


Re: updating multiple records with VBScript and SQL

>Why not split each string into a separate array and then use both
array's to build your update statement. After all, you can run Split
more than once on a page :-)

Sounds great, but I haven't used arrays very often before, and I'm not
sure how I would use both to build the statement.

Let's say I do:

id=Split(id, ",")
name=Split(name, ",")
For x = LBound(id) to UBound(id)
statement = statement & "UPDATE table SET name = '" & name & "' WHERE
id = '" & id & "';"
Next

How does it know to iterate through the name array along with the id
array?

- Amanda



*** Sent via Developersdex http://www.examnotes.net ***

Report this thread to moderator Post Follow-up to this message
Old Post
Amanda Hallock
05-26-05 01:55 AM


Re: updating multiple records with VBScript and SQL
Amanda,

Try:

idArray=Split(id, ",")
nameArray=Split(name, ",")
For x = LBound(idArray) to UBound(idArray)
statement = statement & "UPDATE table SET name = '" & nameArray(x) & "'
WHERE id = '" & idArray(x) & "';"
Next

Dave


"Amanda Hallock" <amanda2@southwind.org> wrote in message
news:ONrqczVYFHA.3840@tk2msftngp13.phx.gbl...
> 
> array's to build your update statement. After all, you can run Split
> more than once on a page :-)
>
> Sounds great, but I haven't used arrays very often before, and I'm not
> sure how I would use both to build the statement.
>
> Let's say I do:
>
> id=Split(id, ",")
> name=Split(name, ",")
> For x = LBound(id) to UBound(id)
> statement = statement & "UPDATE table SET name = '" & name & "' WHERE
> id = '" & id & "';"
> Next
>
> How does it know to iterate through the name array along with the id
> array?
>
> - Amanda
>
>
>
> *** Sent via Developersdex http://www.examnotes.net ***



Report this thread to moderator Post Follow-up to this message
Old Post
DrBarkley
05-26-05 01:55 AM


Re: updating multiple records with VBScript and SQL
Thanks a bunch Dave, worked like a charm.  -Amanda



*** Sent via Developersdex http://www.examnotes.net ***

Report this thread to moderator Post Follow-up to this message
Old Post
Amanda Hallock
05-26-05 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:32 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.