Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 4th, 2005, 12:49 AM
Authorized User
 
Join Date: Jun 2003
Location: Melbourne, Victoria, Australia.
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default inserting records with foreign and primary keys

Hi all,

im really flustered at this one.... Im having problems doing simple insert statement into a Sybase sql anywhere database.

The error im getting is:

Code:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Sybase][ODBC Driver]Integrity constraint violation: no primary key value for foreign key 'MemberCode' in table 'PersonMember'
/admin/Member_New-Sybase.asp, line 39
What i am doing is first i have added a record to my persons table the next step is i need to add this person id to the PersonMember table with a new MemberCode and then finally add more information to a membership table.

I insert the data into the persons table fine then the above error appears and i don't know why?

Any help with this issue would be much appreciated.

Regards,

Tim

Full code
Code:
<%
' create new person and member on Sybase table: person, PersonMember, Membership
' get mysql record
Membership_ID = Request.QueryString("ID")
ActivationCode = Request.QueryString("ActivationCode")

If IsNumeric(Membership_ID) = False OR Len(Membership_ID) <= 0 Then
Response.Redirect("Error.asp")
End If

strSQL = "SELECT membership.*, membership_details.* FROM membership, membership_details WHERE membership.Membership_ID = "& Membership_ID &" AND membership.ActivationCode = '"& ActivationCode &"' AND membership.Membership_ID = membership_details.Membership_ID"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, adForwardOnly, adLockReadOnly, adCmdText
'Validate and get required variables
' current date
JoinDate = DatePart("yyyy", Date) & "-" & DatePart("m", Date) & "-" & DatePart("d", Date)
' set null dates
If Len(objRS("DOB")) <= 0 OR IsDate(objRS("DOB")) Then
DOB = DatePart("yyyy", "0000") & "-" & DatePart("m", "00") & "-" & DatePart("d", "00")
End If

'## Step 1: Add to Sybase: person
' call next person id from sybase based on location
NewPersonID = PersonID(objRS("Location"))
strAdd = "INSERT INTO ""dba"".""person"" (UMC, Title, FirstName, LastName, Affiliate, DofB, DateJoined, Address1, Suburb, State, PCode, PostAddr1, PostSuburb, PostState, PostPCode, HMPhone, Mobile, EMail, Judge, Occupation, PensionNo) VALUES ("&NewPersonID&", '"&objRS("Prefix")&"', '"&objRS("FirstName")&"', '"&objRS("LastName")&"', "& 0 &", '"&DOB&"', '"&JoinDate&"', '"&objRS("Address")&"', '"&objRS("City")&"', '"&objRS("Location")&"', '"&objRS("PostCode")&"', '"&objRS("PAddress")&"', '"&objRS("PCity")&"', '"&objRS("PLocation")&"', '"&objRS("PPostCode")&"', '"&objRS("Phone")&"', '"&objRS("Mobile")&"', '"&objRS("Email")&"', "& 0 &", '"&objRS("Occupation")&"', '"&objRS("PensionNumber")&"')"
cn.Execute(strAdd)
' call next member id
NewMemberID = MemberID(objRS("Location"))
' ## Step 2: add to Sybase: PersonMember

Vote = 0
strAdd = "INSERT INTO ""dba"".""PersonMember"" (MemberCode, UMC, EntryDate, Vote) VALUES ('"&NewMemberID&"', '"&NewPersonID&"', '"&JoinDate&"', "&Vote&")"
cn.Execute(strAdd)
' Step 3: add to Sybase: Membership

MemName = objRS("Prefix") & " " & objRS("FirstName") & " " & objRS("LastName")
DatePaid = DatePart("yyyy", objRS("StartDate")) & "-" & DatePart("m", objRS("StartDate")) & "-" & DatePart("d", objRS("StartDate"))
Journal = 0
Nominee = 0
strAdd = "INSERT INTO ""dba"".""Membership"" (MemberCode, MemClass, MemStatus, StatusDate, MemName, StartDate, Duration, Journal, Amount, DatePaid, Nominee, Recipient, MemRestart) VALUES ("&NewMemberID&", '"&MemClass&"', 'N', '"&DatePaid&"', '"&MemName&"', '"&DatePaid&"', "&objRS("Duration")&", "&Journal&", "&objRS("Amount")&", '"&DatePaid&"', "&Nominee&", "&NewPersonID&", '"&DatePaid&"')"
'cn.Execute(strAdd)


objRS.Close
Set objRS = Nothing
%>
TDA
__________________
TDA
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Design: Foreign Key to Multiple Primary Keys? kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 10 May 8th, 2008 04:14 PM
list foreign keys jomet Oracle 2 March 28th, 2008 04:17 AM
Copying Databases & Foreign Keys donevco Access 5 February 20th, 2007 08:31 AM
When to define primary keys and foregin keys? method SQL Server 2000 1 August 26th, 2005 09:14 AM
transfering identites as foreign keys santaji SQL Server DTS 1 September 23rd, 2003 09:28 AM



All times are GMT -4. The time now is 04:34 PM.


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