Delete problem in oledb for vb.net

R

Ryan McConnell

Hi,
I'm trying to delete a record from an access database.
I've displayed the records from a database on screen with a button to
delete the current if clicked.
When i run the code below i get a message saying the following

Index #0
Message: Syntax error (missing operator) in query expression
'interactionid = 8f1b1db-93d6-474c-9314-b8c33f13b448'.
NativeError: -524553244
Source: Microsoft JET Database Engine
SQLState: 3075

What am i doing wrong?

Private Sub DeleteProduct()
Dim cnn As OleDbConnection
Dim cmd As OleDbCommand
Dim oleStatement As String
Dim rowsAffected As Integer
Dim paramdel As String
Try
paramdel = CStr(TextBox1.Text)
' Build the DELETE command.
oleStatement = "DELETE FROM interactiontable WHERE
interactionid = " & paramdel

cnn = New OleDbConnection(connectionString)
cmd = New OleDbCommand(oleStatement, cnn)

cnn.Open()
rowsAffected = cmd.ExecuteNonQuery()
cnn.Close()


If rowsAffected > 0 Then
MsgBox("Service successfully deleted.",
MsgBoxStyle.OKOnly Or MsgBoxStyle.Information, Me.Text)
Else
MsgBox("Delete Failed. interaction id " &
TextBox1.Text & _
" not found.", MsgBoxStyle.OKOnly Or
MsgBoxStyle.Critical, Me.Text)
End If



Catch e As OleDbException
Dim errorMessages As String
Dim i As Integer

For i = 0 To e.Errors.Count - 1
errorMessages += "Index #" & i.ToString() &
ControlChars.Cr _
& "Message: " & e.Errors(i).Message &
ControlChars.Cr _
& "NativeError: " &
e.Errors(i).NativeError & ControlChars.Cr _
& "Source: " & e.Errors(i).Source &
ControlChars.Cr _
& "SQLState: " & e.Errors(i).SQLState &
ControlChars.Cr
Next i

MsgBox(errorMessages, MsgBoxStyle.Critical, Me.Text)
End Try




End Sub





Thanks!
Ryan McConnell
 
A

Armin Zingler

Ryan McConnell said:
Hi,
I'm trying to delete a record from an access database.
I've displayed the records from a database on screen with a button
to delete the current if clicked.
When i run the code below i get a message saying the following

Index #0
Message: Syntax error (missing operator) in query expression
'interactionid = 8f1b1db-93d6-474c-9314-b8c33f13b448'.
NativeError: -524553244
Source: Microsoft JET Database Engine
SQLState: 3075

What am i doing wrong?

Use the Parameters property of your OleDBCommand to avoid this error.

More ADO.NET related questions:
microsoft.public.dotnet.framework.adonet



--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 

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