|
-
Jun 5th, 2005, 07:00 AM
#1
Thread Starter
Fanatic Member
Can't figure out the error
VB Code:
Dim SQLUpdateStr As String
'SQL Update string
SQLUpdateStr = "UPDATE Staff SET Address = @Address, BookingRights = @BookRight," & _
"Contract = @Contract, DOB = @DOB, Forename = @Forename, Gender = @Gender," & _
"LoginRights = @LoginRight, ManageRights = @ManageRight, MemberRights = @MemberRight," & _
"Position = @Position, Postcode = @Postcode, Salary = @Salary, StartDate = @StartDate," & _
"Surname = @Surname, [Telephone Number] = @TelNum"
[B]'Set SQL statements
daStaff.DeleteCommand.CommandText = "DELETE FROM Staff" 'Delete statement
daStaff.InsertCommand.CommandText = "INSERT INTO Staff" 'Insert statement
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.
-
Jun 5th, 2005, 07:08 AM
#2
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
-
Jun 5th, 2005, 09:23 AM
#3
Thread Starter
Fanatic Member
Re: Can't figure out the error
 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:
'Create instances of OLEDB commands
Dim cmdSQLDel As New OleDbCommand("DELETE FROM Staff WHERE EmployeeID = @EmpID") 'Delete statement
Dim cmdSQLIns As New OleDbCommand("INSERT INTO Staff") 'Insert statement
Dim cmdSQLUpd As New OleDbCommand(SQLUpdateStr) 'Update statement
'Set SQL statements
With daStaff
.DeleteCommand = cmdSQLDel
.InsertCommand = cmdSQLIns
.UpdateCommand = cmdSQLUpd
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|