Results 1 to 3 of 3

Thread: [URGENT] OledbCommand Parameters Not Working - HELP!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    [URGENT] OledbCommand Parameters Not Working - HELP!

    vb Code:
    1. Public Function CreateDatabase(ByVal DBDirectory As String) As Boolean
    2.         With frmNewEditCourse
    3.             Dim DB As New ADOX.Catalog()
    4.             Try
    5.                 DB.Create(Connection.ConnectionString)
    6.                 SQL = "CREATE TABLE [Information] ([CIndex] AutoIncrement, [CourseCode] TEXT, [RoomNumber] TEXT, [SchoolYear] TEXT, [Teacher] Text)"
    7.                 Command = New OleDbCommand(SQL, Connection)
    8.                 Command.Connection.Open()
    9.                 Command.ExecuteNonQuery()
    10.                 Command.CommandText = "INSERT INTO [Information] (CourseCode, RoomNumber, SchoolYear, Teacher) VALUES(@CourseCode, @RoomNumber, @SchoolYear, @Teacher)"
    11.                 Command.Parameters.AddWithValue("@CourseCode", .txtCourseCode.Text)
    12.                 Command.Parameters.AddWithValue("@RoomNumber", .txtRoomNumber.Text)
    13.                 Command.Parameters.AddWithValue("@SchoolYear", .txtSchoolYear.Text)
    14.                 Command.Parameters.AddWithValue("@Teacher", .txtTeacher.Text)
    15.                 Command.Connection.Close()
    16.                 MsgBox("Done")
    17.             Catch Excep As System.Runtime.InteropServices.COMException
    18.  
    19.             Finally
    20.                 DB = Nothing
    21.             End Try
    22.         End With
    23.     End Function

    Theirs my Function, what it does is it creates a Database and then its suppose to write the values into the database. Its creating it, but its just not inserting the values into the Table. Why?

    Edit:

    No Errors Occur and the MsgBox does show up.
    Last edited by Wesley008; Sep 24th, 2008 at 06:56 PM.

  2. #2
    Lively Member
    Join Date
    Jul 2008
    Posts
    107

    Re: [URGENT] OledbCommand Parameters Not Working - HELP!

    Wesley008,

    You are never executing the Insert command.

    After you have added all the parameters and before you close the connection:

    Command.ExecuteNonQuery()

    Kerry Moorman

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    Re: [URGENT] OledbCommand Parameters Not Working - HELP!

    Wow. Thank You. I'm kinda getting new to the Parameters so I thought I didn't need to Execute

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