SunQuest
 
           ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old April 29th, 2008, 02:04 PM
geino geino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 3 geino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 4 sec
Reputation Power: 0
Cannot add or change a record because a related record is required

I am getting an error when I try to write more than one record to an Access Database. The first record writes properly, but it fails on the second and any additional records. The phone numbers are correct so I am uncertian why I am getting the error

set conn = Server.CreateObject("ADODB.Connection")
conn.Open = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\cellphone\NewCellPhone.m db"

For i=0 to UBound(splitMonthlyService)
totalCharges = formatcurrency((cdbl(splitMonthlyService(i)) + cdbl(splitUsageCharges(i)) + cdbl(splitCreditAdj(i)) + cdbl(splitTaxFees(i)) + cdbl(splitNonComm(i))),2)

Response.Write ("<br>" & invoiceNumber & " " & splitPhoneNumber(i) & " " & splitMonthlyService(i) & "<br>")
Response.Write (IDnumber & "<br>")
sql="INSERT INTO SummaryOfCurrentCharges (ID,Invoice_Number,Phone_Number,Monthly_Service_Ch arge,Charges_and_Credits,Usage_Charges,Equiptment_ Charges,Subscriber_Surcharges,Taxes_surcharges_and _fees,Adjustments,Other_Minute_Charges,Direct_Conn ect_Charges,Message_Charges,Data_Charges,Directory _Assistant,Total_Charges,Account_Number)"

sql=sql & " VALUES "
sql=sql & "('" & IDnumber & "',"
sql=sql & "'" & invoiceNumber & "',"
sql=sql & "'" & splitPhoneNumber(i) & "',"
sql=sql & "'" & splitMonthlyService(i) & "',"
sql=sql & "'" & splitCreditAdj(i) & "',"
sql=sql & "'" & splitUsageCharges(i) & "',"
sql=sql & "'" & EqptCharges & "',"
sql=sql & "'" & splitNonComm(i) & "',"
sql=sql & "'" & splitTaxFees(i) & "',"
sql=sql & "'" & Adjustments & "',"
sql=sql & "'" & otherMinutes & "',"
sql=sql & "'" & directConnect & "',"
sql=sql & "'" & messageCharges & "',"
sql=sql & "'" & dataCharges & "',"
sql=sql & "'" & directoryAssist & "',"
sql=sql & "'" & totalCharges & "',"
sql=sql & "'" & accountNumber & "')"

conn.Execute sql,recaffected

if err<>0 then
Response.Write ("<br>" & err)
Response.Write(" " & err.Description)
else
Response.Write("<h3>" & recaffected & " invoice added</h3>")
end if
IDnumber = IDnumber + 1
Next

Response.Write(rowCount)
conn.close

----------------------------

The output:

ACCOUNTX4223098 (999) 555-4599 $74.99
10863

1 invoice added

ACCOUNTX4223098 (999) 555-5168 $49.99
10864

-2147467259 You cannot add or change a record because a related record is required in table 'CellPhoneNumbers'.

This error is repeated for each additional record

Any help is appriciated.
Thanks
geino

Reply With Quote
  #2  
Old May 2nd, 2008, 02:05 AM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Click here for more information. Click here for more information
 
Join Date: Apr 2008
Posts: 195 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 1 h 11 m 12 sec
Reputation Power: 1
The error is telling you that the underlying database has a foreign key relationship between the two tables CellPhoneNumbers and SummaryOfCurrentCharges that isn't being met during your insert.

Also, although the ";" isn't necessarily required you should add it to the end of your sql statement to make sure the statement is interpreted correctly.

The only other question would be does the Invoice number need to be unique?

Reply With Quote
  #3  
Old May 2nd, 2008, 02:10 PM
geino geino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 3 geino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 4 sec
Reputation Power: 0
Quote:
Originally Posted by dykebert
The error is telling you that the underlying database has a foreign key relationship between the two tables CellPhoneNumbers and SummaryOfCurrentCharges that isn't being met during your insert.

Also, although the ";" isn't necessarily required you should add it to the end of your sql statement to make sure the statement is interpreted correctly.

The only other question would be does the Invoice number need to be unique?


Thank you. I managed to solve the problem by addressing another issue I was having. The format of the telephone number was (999) 555-4599 - The space was creating other problems. So I chose to reload the phone number from the database on the second page instead of passing it from the first page. This solved the problem above and it solve the format issue with the phone phone number.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Cannot add or change a record because a related record is required


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway