473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Delete problem in oledb for vb.net

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
Nov 20 '05 #1
2 3401
Hi,

Try this.
paramdel = "'" & TextBox1.Text & "'"

Ken
-----------------------
"Ryan McConnell" <ji********@hotmail.com> wrote in message
news:18**************************@posting.google.c om...
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

Nov 20 '05 #2
"Ryan McConnell" <ji********@hotmail.com> schrieb
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

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Grant | last post by:
Hello, How come when I add a new row to my dataset table it shows up as changed (agencyData.Haschanges() = True) but when I delete a row the dataset thinks here are no...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
3
by: Phi | last post by:
Hi, I hope somebody could help me with this problem. I would like to make a form to add and delete records from my ms access database. I've found most of the codes from the internet and...
1
by: alan | last post by:
in my project there are 5 textbox : tbOrderid, tbSeqNum, tbFoodCode, tbFoodDesc and tbPrice 9 button: btInsert, btdelete, btUpdate, btClear, btBind, btFirst, btPrevious, btNext and btLast i...
0
by: Hyphessobrycon | last post by:
hallo, why doesn't this function? Only when I select the datarow, push the delete button of the keyboard and then the btnrubriekweg button. why not immediately from the rubriekweg button only?...
7
by: travlintom | last post by:
Hi. I'm new to VB.net and am used to working with recordsets (much easier). I have a datagrid that, when the user double clicks on a row, I am giving them a chance to delete it. I thought this...
12
by: Will Lastname | last post by:
I have a windows application that displays users from access database in a checkboxlist. What I am attempting to do is select a user or users from the checkboxlist, loop through, and delete their...
12
by: dennist685 | last post by:
Can't edit, delete or add row in an Access database in a website 2003 When I implement a walkthrough using Northwind I have no trouble doing this. Also, in a windowsforms project I have no...
4
by: darrel | last post by:
I'm still struggling to find out why I keep getting Invalid object name 'monkey'. errors. Below is my try/catch statement. Note the first query is trying to delete a record in the table...
5
by: John7000 | last post by:
Hello, I am amateur with VB database usage. I've written a little database that keeps track of names, address, phone numbers etc. It displays the data in a DataGrid and stores them in a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.