我编写了插入和更新表 student_record_database 的代码,该表有许多其他表的外键。
运行此代码时,它不接受从组合框中选择的文本数据,并给出错误无效数字、完整性约束和 DTpicker 也不接受给定日期,尽管我设置了自定义格式。
下面是我的代码。我在组合框中显示文本时遇到问题。
<code>
Private Sub save_Click()
If Val(COMBO4) = 0 Then
SQL = "INSERT INTO STUDENT_RECORD_DATABASE(ROLLNO,FIRST_NAME,MIDDLE_NAME,LAST_NAME,CONTACT,CONTACT1,CONTACT2,ADDRESS,GRADE,DIVID,BLOOD_GROUP,HID,DATE_OF_BIRTH,TRANSPORT,SNAME,MEAL,BUSNO,RUTNO,DID,AID,CARD_TYPE,CARD_NO)"
SQL = SQL + "VALUES(" & Val(COMBO4) & ",'" & Trim(Text2) & "', '" & Trim(Text3) & "', '" & Trim(Text4) & "', " & Val(Text5) & ", " & Val(Text6) & ", " & Val(Text7) & ", '" & Trim(Text8) & "', '" & Trim(Combo1) & "','" & Val(Combo2) & "',"
SQL = SQL + " '" & Trim(Combo3) & "' ,'" & Val(Combo9) & "','" & DTPicker1.Value & "',"
SQL = SQL + " '" & Trim(Combo10) & "' ,'" & Combo5.Text & "' ,'" & Trim(Combo11) & "' ,'" & Combo6.Text & "' ,'" & Val(Combo12) & "' ,'" & Val(Combo7) & "','" & Val(Combo8) & "',"
SQL = SQL + " '" & Trim(Combo13) & "' ," & Text11.Text & " ) "
Set RES = CON.Execute(SQL)
MsgBox ("RECORD INSERTED")
Else
SQL = "UPDATE STUDENT_RECORD_DATABASE SET "
SQL = SQL + "ROLLNO= " & Val(COMBO4) & ","
SQL = SQL + "FIRST_NAME= '" & Trim(Text2) & "',"
SQL = SQL + "MIDDLE_NAME= '" & Trim(Text3) & "',"
SQL = SQL + "LAST_NAME= '" & Trim(Text4) & "',"
SQL = SQL + "CONTACT=" & Val(Text5) & ","
SQL = SQL + "CONTACT1=" & Val(Text6) & ","
SQL = SQL + "CONTACT2=" & Val(Text7) & ","
SQL = SQL + "ADDRESS= '" & Trim(Text8) & "',"
SQL = SQL + "GRADE='" & Trim(Combo1) & "',"
SQL = SQL + "DIVID='" & Val(Combo2) & "',"
SQL = SQL + "BLOOD_GROUP='" & Trim(Combo3) & "',"
SQL = SQL + "HID='" & Val(Combo9) & "',"
SQL = SQL + "DATE_OF_BIRTH=(' " & DateValue(DTPicker1.Value) & " ' ),"
SQL = SQL + "TRANSPORT='" & Trim(Combo10) & "',"
SQL = SQL + "SNAME='" & Trim(Combo5) & "',"
SQL = SQL + "MEAL='" & Trim(Combo11) & "',"
SQL = SQL + "BUSNO='" & Trim(Combo6) & "',"
SQL = SQL + "RUTNO=" & Val(Combo12) & ","
SQL = SQL + "DID='" & Val(Combo7) & "',"
SQL = SQL + "AID='" & Val(Combo8) & "',"
SQL = SQL + "CARD_TYPE='" & Trim(Combo13) & "',"
SQL = SQL + "CARD_NO=" & Val(Text11) & ""
SQL = SQL + "WHERE ROLLNO= " & Val(COMBO4) & ""
MsgBox ("RECORD UPDATED")
End If
End Sub
</code>
Error occurred is invalid month,integrity constraint-parent key not found,invalid number.