Results 1 to 3 of 3

Thread: Can't figure out the error

  1. #1

    Thread Starter
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Resolved Can't figure out the error

    VB Code:
    1. Dim SQLUpdateStr As String
    2. 'SQL Update string
    3. SQLUpdateStr = "UPDATE Staff SET Address = @Address, BookingRights = @BookRight," & _
    4. "Contract = @Contract, DOB = @DOB, Forename = @Forename, Gender = @Gender," & _
    5. "LoginRights = @LoginRight, ManageRights = @ManageRight, MemberRights = @MemberRight," & _
    6. "Position = @Position, Postcode = @Postcode, Salary = @Salary, StartDate = @StartDate," & _
    7. "Surname = @Surname, [Telephone Number] = @TelNum"
    8. [B]'Set SQL statements
    9. daStaff.DeleteCommand.CommandText = "DELETE FROM Staff" 'Delete statement
    10. daStaff.InsertCommand.CommandText = "INSERT INTO Staff" 'Insert statement
    11. daStaff.UpdateCommand.CommandText = SQLUpdateStr 'Update statement[/B]
    When i run this code i get an error ("Object reference not set to an instance of an object."). I don't know why this error is occuring, but i have found out that the error is in the code i highlighted in bold. Any ideas?
    Last edited by x-ice; Jun 5th, 2005 at 03:16 PM.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: Can't figure out the error

    The *Command objects are not inherent, meaning you do not get them set for you by default. You actually have to instantiate a Command object and set those properties equal to that object.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Fanatic Member x-ice's Avatar
    Join Date
    Mar 2004
    Location
    UK
    Posts
    671

    Re: Can't figure out the error

    Quote Originally Posted by crptcblade
    The *Command objects are not inherent, meaning you do not get them set for you by default. You actually have to instantiate a Command object and set those properties equal to that object.
    Ok i get you, like this.
    VB Code:
    1. 'Create instances of OLEDB commands
    2. Dim cmdSQLDel As New OleDbCommand("DELETE FROM Staff WHERE EmployeeID = @EmpID") 'Delete statement
    3. Dim cmdSQLIns As New OleDbCommand("INSERT INTO Staff") 'Insert statement
    4. Dim cmdSQLUpd As New OleDbCommand(SQLUpdateStr) 'Update statement
    5. 'Set SQL statements
    6. With daStaff
    7.      .DeleteCommand = cmdSQLDel
    8.      .InsertCommand = cmdSQLIns
    9.      .UpdateCommand = cmdSQLUpd
    10. End With
    Last edited by x-ice; Jun 5th, 2005 at 09:34 AM.

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