|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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? |
|
#3
|
|||
|
|||
|
Quote:
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. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Cannot add or change a record because a related record is required |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|