Visual basic problem: Object variable or With block variable not set.

Joined
Nov 26, 2009
Messages
1
Reaction score
0
Hi, if anyone could help, id be mightly greatful, Im a beginner at this stuff so not the most experienced but Im starting to get my head round things in VB.

Anyhow Im getting the error thats above:

Object variable or With block variable not set.


wehn trying to delete a single record from a table: here is the current code i have trying to achieve this operation:


sql = "Delete from Fault where TechID='" & TechIDM & "'"

Dim commandDelete As New OdbcCommand(sql)

Using connection As New OdbcConnection(constring)

commandDelete.Connection = connection

connection.Open()

commandDelete.ExecuteNonQuery()

connection.Close()

End Using

'Messagebox to give secure check to user about deleting data
If MsgBox("Are you sure you wish to proceed?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then

commandDelete.Connection = connection

connection.Open()

commandDelete.ExecuteNonQuery()

connection.Close()

End If


error comes up on highlighted text. if anyone can shed some light on this id be so greatful, thank you to anyone who can help


Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top