Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2005, 03:22 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update records with multiple keys (ASP VBScript)

In my table I have created a primary key on the combination of two fields. I use a command to update this table. The problem is that one of the fields i'm going to update is a part of the primary key. I get no error message, but the current record is not updated. When i try to update the record without changing the field which is a part of the primary key everything works fine.

The table-design and Dreamweaver command is shown below:

Tablename = tbl_Place_of_work
Employeeid - Int - 4
Phonenumber - varchar - 20
Division - char - 5
Sphere - varchar - 70

The combination of Employeeid And Division are the primary key

SQL
UPDATE dbo.tbl_Place_of_work
SET Phonenumber = 'varPhonenumber', Division = 'varDivision', Sphere = 'varSphere'
WHERE Employeeid = varEmployeeid AND Division = 'varDivision'

Variables
varPhonenumber = Request("Phonenumber")
varDivision = Request("Division")
varSphere = Request("Sphere")
varEmployeeid = Request("Employeeid")

My Regards,
Rune

 
Old April 27th, 2005, 03:43 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rune,

From the code it seems that it is not going to udate the record when the value in the Division changes.

"WHERE Employeeid = varEmployeeid AND Division = 'varDivision' "

This is bcoz you are in the where clause you are using the changed value of division. You should use the old value.

I think this is the issue





 
Old April 27th, 2005, 04:23 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much for your help.

I changed the where clause to

"WHERE Employeeid = varEmployeeid AND Division = Division"

Works fine now. Thanks again

My Regards,
Rune

 
Old April 27th, 2005, 04:53 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rune,

If you are giving " Division = Division " rather than seomthing like " Division = varOldDivision ", It is going to be update all the divisions the an Employeeid.

Regards
Prashant






 
Old April 27th, 2005, 05:28 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ooops. Thanks for reminding me.

Rune






Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Multiple Records cancer10 Classic ASP Databases 0 October 25th, 2006 01:01 AM
Update records with multiple keys (ASP VBScript) rbrynest Dreamweaver (all versions) 1 April 27th, 2005 05:11 AM
update multiple records mateenmohd Classic ASP Basics 4 June 28th, 2004 03:38 AM
How Can I Update Multiple Records Lucy SQL Server ASP 3 March 18th, 2004 03:19 PM
update multiple records (solved) dhaywirex Classic ASP Databases 2 February 24th, 2004 12:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.