parent key not found
--------------------------------------------------------------------------------
plz help me
i am using two table topmaster and reply topid is primary key in topmaster and topid and repid is foreign key in reply table
if one record in topmaster topid=1 then one record is submitted in reply table topid=1 repid=1 but antother now submitted second record topid=1 and repid=2 then error is parent key not found
id second record submit in topmster topid=2 then next one more record can submit in reply topid=1 or 2 and repid=2
so problems is before submition of record it serched topmaster table how many records in it is more then reply master table if yes then send error else submit record
so how can solve the problem
my code for submit in reply table is
code(asp):-
<%
R.Open "Select rep_id from reply order by rep_id", conn, adOpenStatic, adLockOptimistic, adCmdText
If R.Recordcount > 0 Then
R.Movelast
vrepid = R("rep_id")
vrepid = CInt(vrepid) + 1
Else
vrepid = 1
End if
R.Close
If Not IsEmpty(Request.Form("submit")) then
vtopid=request.form("vtopid")
vreply = Request.Form("vreply")
vtopid=trim(vtopid)
vrepid = trim(vrepid)
vreply = trim(vreply)
If len(errorMsg) = 0 Then
If len(vreply) = 0 Then
errorMsg = "Your must enter your Reply"
Elseif len(vreply) > 500 Then
errorMsg = "The voice you are entered is not longer than 500 characters. Please reduce the size."
End If
End If
If len(errorMsg) = 0 Then
conn.Close
conn.Mode = adModeReadWrite
conn.Open
R.Open "Select * from reply ", conn, adOpenStatic, adLockOptimistic, adCmdText
R.Addnew
R("top_id") =vtopid
R("rep_id") = vrepid
R("rep_by") = request.cookies("userid")
R("rep_dt") = Cdate(date())
R("reply") = vreply
R.UPdate
R.Close
Response.Redirect "voicereply.asp"
end if
end if