this is the error message...
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Admission_Record_PT_Chart". The conflict occurred in database "HospitalManagementSystem", table "dbo.PT_Chart", column 'Chart_ID'.
The statement has been terminated.
my code is
Imports System.Data.SqlClient
Public Class Admission
Private cs As New SqlConnection("Data Source=SAbio;Initial Catalog=HospitalManagementSystem;User ID=sa;Password=TRACERT123")
Private da As New SqlDataAdapter("SELECT * FROM Admission_Record", cs)
Private ds As New DataSet
Private cmd As New SqlCommandBuilder(da)
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
da.InsertCommand = New SqlCommand("INSERT INTO Admission_Record VALUES(@IPD_ID, @LName, @FName,@MName, @Address, @Birthplace, @Birthdate, @Age, @Sex, @Room_ID, @CivilStatus, @Nationality, @Religion, @Date_Admitted, @Date_Discharged, @Time_Admitted, @Time_Discharged, @Chart_ID, @Occupation)", cs)
da.InsertCommand.Parameters.Add("@IPD_ID", SqlDbType.VarChar).Value = TxtIPD_ID.Text
da.InsertCommand.Parameters.Add("@LName", SqlDbType.VarChar).Value = TxtLName.Text
da.InsertCommand.Parameters.Add("@FName", SqlDbType.VarChar).Value = TxtFName.Text
da.InsertCommand.Parameters.Add("@MName", SqlDbType.VarChar).Value = TxtMName.Text
da.InsertCommand.Parameters.Add("@Address", SqlDbType.VarChar).Value = TxtAddress.Text
da.InsertCommand.Parameters.Add("@Birthplace", SqlDbType.VarChar).Value = TxtBirthplace.Text
da.InsertCommand.Parameters.Add("@Birthdate", SqlDbType.VarChar).Value = TxtBirthdate.Text
da.InsertCommand.Parameters.Add("@Age", SqlDbType.VarChar).Value = TxtAge.Text
da.InsertCommand.Parameters.Add("@Sex", SqlDbType.VarChar).Value = cbSex.Text
da.InsertCommand.Parameters.Add("@Room_ID", SqlDbType.VarChar).Value = TxtRmID.Text
da.InsertCommand.Parameters.Add("@CivilStatus", SqlDbType.VarChar).Value = cbCStatus.Text
da.InsertCommand.Parameters.Add("@Nationality", SqlDbType.VarChar).Value = TxtNationality.Text
da.InsertCommand.Parameters.Add("@Religion", SqlDbType.VarChar).Value = TxtReligion.Text
da.InsertCommand.Parameters.Add("@Date_Admitted", SqlDbType.VarChar).Value = TxtDate_Admitted.Text
da.InsertCommand.Parameters.Add("@Date_Discharged", SqlDbType.VarChar).Value = TxtDate_Discharged.Text
da.InsertCommand.Parameters.Add("@Time_Admitted", SqlDbType.VarChar).Value = TxtTime_Admitted.Text
da.InsertCommand.Parameters.Add("@Time_Discharged", SqlDbType.VarChar).Value = TxtTime_Discharged.Text
da.InsertCommand.Parameters.Add("@Chart_ID", SqlDbType.VarChar).Value = TxtChart_ID.Text
da.InsertCommand.Parameters.Add("@Occupation", SqlDbType.VarChar).Value = txtOccupation.Text
cs.Open()
da.InsertCommand.ExecuteNonQuery()
cs.Close()
End Sub
what do i do if i'm gonna put a blank on a field? if i leave it as null?