Greetings, can someone please give me an idea on how to make a stored procedure with foreign key. Here's what i want to happen.

1) I have 1 button for Adding patient.
2) On the add patient button, i want to Add the patient information on the tblPatient and insert the p_ID on the tblRecord.
2) After i add it on the tblPatient, the p_ID should also go to the tblRecord.

`@patientFname varchar(60), @patientIname varchar(20), @patientLname varchar(50),
@patientHaddress varchar(100), @patientPaddress varchar(50), @Dob date, @gender varchar(10), @contactNo varchar(10), @p_ID int,
@tCount varchar(5), @details varchar(50)

AS

INSERT INTO tblPatient(patientFname,patientIname,patientLname,patientHaddress,patientPaddress,Dob,gender,contactNo)
VALUES(@patientFname, @patientIname, @patientLname, @patientHaddress, @patientPaddress, @Dob, @gender, @contactNo)

SELECT p_ID = SCOPE_IDENTITY()

        INSERT INTO tblRecord (p_ID,  tCount, details)
        VALUES (@p_ID,  @tCount, @details)`
`heres the code for adding the patient.

`With dbComm
            .AddParameter("@patientFname", firstnameTb.Text, SqlDbType.VarChar)
            .AddParameter("@patientIname", miTb.Text, SqlDbType.VarChar)
            .AddParameter("@patientLname", lastnameTb.Text, SqlDbType.VarChar)
            .AddParameter("@patientHaddress", homeAddressTb.Text, SqlDbType.VarChar)
            .AddParameter("@patientPaddress", pAddress.Text, SqlDbType.VarChar)
            .AddParameter("@Dob", dobPicker.Text, SqlDbType.Date)
            .AddParameter("@gender", genderCmbx.Text, SqlDbType.VarChar)
            .AddParameter("@contactNo", mobileContactTb.Text, SqlDbType.VarChar)
            .AddParameter("@tCount", ListView1.Items(0).SubItems(0).Text, SqlDbType.VarChar)
            .AddParameter("@details", ListView1.Items(0).Text, SqlDbType.VarChar)
            .ExecuteStoredProcedure("insertPatient")

            If .Success = False Then
                Dim SAPI
                SAPI = CreateObject("SAPI.spvoice")
                SAPI.speak("The system wasn't able to insert the data in the database.")
            Else
                Dim SAPI
                SAPI = CreateObject("SAPI.spvoice")
                SAPI.speak("Patient is successfully registered.")
            End If
        End With``
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.