Updating database with foreign keys
I am doing a program in school that keeps track on enrollment for a fake school
So far i can add/update/view Students and Instructors
But when i try to add a new course using the same code it doesn't work.
the only difference i can see is that the Course table on the data base as a foreign key from the Instructor table
Would that affect the way i have to code the Add and update functions of my courses class?
this is what i have right now
VB Code:
Public Function Update() As Boolean
Dim isSuccessful As Boolean
Dim conn As New SqlConnection(connstring)
Dim sql As String = "UpdateCourse"
comm = New SqlCommand(sql, conn)
comm.CommandType = CommandType.StoredProcedure
comm.Parameters.Add(New SqlParameter("@COURSECODE", Me.mCourseCode))
comm.Parameters.Add(New SqlParameter("@COURSENAME", Me.mCourseName))
comm.Parameters.Add(New SqlParameter("@INSTRUCTORID", Me.mInstructorId))
Try
conn.Open()
comm.ExecuteNonQuery()
isSuccessful = True
Catch ex As Exception
isSuccessful = False
End Try
Return isSuccessful
End Function
my storedprocedure is
VB Code:
ALTER PROCEDURE dbo.UpdateCourse
@COURSECODE varchar(30),
@COURSENAME varchar(30),
@INSTRUCTORID bigint
AS
UPDATE Course SET CourseName=@COURSENAME, InstructorID=@INSTRUCTORID
WHERE CourseCode=@COURSECODE
I am using sqlServer 2005 and visual studio 2005
Re: Updating database with foreign keys
Are you getting an error message?
Are you sure that mCourseCode has a valid value?
Is your function returning true or false?
If it is returning false, log the ex.Message somewhere, so you can see the error.