Results 1 to 2 of 2

Thread: Updating database with foreign keys

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    4

    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:
    1. Public Function Update() As Boolean
    2.         Dim isSuccessful As Boolean
    3.         Dim conn As New SqlConnection(connstring)
    4.         Dim sql As String = "UpdateCourse"
    5.         comm = New SqlCommand(sql, conn)
    6.         comm.CommandType = CommandType.StoredProcedure
    7.         comm.Parameters.Add(New SqlParameter("@COURSECODE", Me.mCourseCode))
    8.         comm.Parameters.Add(New SqlParameter("@COURSENAME", Me.mCourseName))
    9.         comm.Parameters.Add(New SqlParameter("@INSTRUCTORID", Me.mInstructorId))
    10.        
    11.         Try
    12.             conn.Open()
    13.             comm.ExecuteNonQuery()
    14.             isSuccessful = True
    15.         Catch ex As Exception
    16.             isSuccessful = False
    17.         End Try
    18.         Return isSuccessful
    19.     End Function

    my storedprocedure is

    VB Code:
    1. ALTER PROCEDURE dbo.UpdateCourse
    2.  
    3. @COURSECODE varchar(30),
    4. @COURSENAME varchar(30),
    5. @INSTRUCTORID bigint
    6. AS
    7. UPDATE Course       SET CourseName=@COURSENAME, InstructorID=@INSTRUCTORID
    8.                     WHERE CourseCode=@COURSECODE

    I am using sqlServer 2005 and visual studio 2005

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width