473,396 Members | 2,050 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,396 software developers and data experts.

Syntax error in update statement - novice question

Hi,

I am trying to update an access database using an SQL statement, I keep
getting an syntax error in update statment. I am passing in strChkBoxValue
as a string value which is declared in another function. Could someone help
me fix my code.

Sean
Dim oComm As OleDbDataAdapter
Dim sConn As String
Dim oDataSet As New DataSet
Dim word as string

'Build the connection string
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
sConn += "Data Source =" & Server.MapPath("email.mdb") & ";"
sConn += "Persist Security Info=False"
Dim strSQL as String = _
"Update members Set Email='" & _
strChkBoxValue & "', " & _
"' WHERE email='" & cstr(strChkBoxValue)

Dim oConn as New OleDBConnection(sConn)
Dim objCmd as New OLEDBCommand(strSQL, oConn)

oConn.open
objCmd.ExecuteNonQuery()
oConn.Close
Nov 18 '05 #1
2 1262
Could you post the response.Write of your SqlString.
But it appears it is false. Too many single quotes and comma.
So one reason could be this.
Yours is :
Dim strSQL as String = "Update members Set Email='" & strChkBoxValue & "', '
WHERE email='" & cstr(strChkBoxValue)

Dim strSQL as String = "Update members Set Email='" & strChkBoxValue & "'
WHERE email='" & cstr(strChkBoxValue) & "'"

Second is what the point to change the value of the email only when the
email is equal to the new value. It wont change anything as the new value
equals the old one.

G
"sean" <se********@shopsmart.com.au> wrote in message
news:uB**************@TK2MSFTNGP09.phx.gbl...
Hi,

I am trying to update an access database using an SQL statement, I keep
getting an syntax error in update statment. I am passing in strChkBoxValue
as a string value which is declared in another function. Could someone help me fix my code.

Sean
Dim oComm As OleDbDataAdapter
Dim sConn As String
Dim oDataSet As New DataSet
Dim word as string

'Build the connection string
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
sConn += "Data Source =" & Server.MapPath("email.mdb") & ";"
sConn += "Persist Security Info=False"
Dim strSQL as String = _
"Update members Set Email='" & _
strChkBoxValue & "', " & _
"' WHERE email='" & cstr(strChkBoxValue)

Dim oConn as New OleDBConnection(sConn)
Dim objCmd as New OLEDBCommand(strSQL, oConn)

oConn.open
objCmd.ExecuteNonQuery()
oConn.Close

Nov 18 '05 #2
You're missing the last single quote after the words "' WHERE email='" &
cstr(strChkBoxValue)

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"sean" <se********@shopsmart.com.au> wrote in message
news:uB**************@TK2MSFTNGP09.phx.gbl...
Hi,

I am trying to update an access database using an SQL statement, I keep
getting an syntax error in update statment. I am passing in strChkBoxValue
as a string value which is declared in another function. Could someone help me fix my code.

Sean
Dim oComm As OleDbDataAdapter
Dim sConn As String
Dim oDataSet As New DataSet
Dim word as string

'Build the connection string
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
sConn += "Data Source =" & Server.MapPath("email.mdb") & ";"
sConn += "Persist Security Info=False"
Dim strSQL as String = _
"Update members Set Email='" & _
strChkBoxValue & "', " & _
"' WHERE email='" & cstr(strChkBoxValue)

Dim oConn as New OleDBConnection(sConn)
Dim objCmd as New OLEDBCommand(strSQL, oConn)

oConn.open
objCmd.ExecuteNonQuery()
oConn.Close

Nov 18 '05 #3

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

Similar topics

3
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: ...
7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
5
by: S.Patten | last post by:
Hi, I have a problem with updating a datetime column, When I try to change the Column from VB I get "Incorrect syntax near '942'" returned from '942' is the unique key column value ...
4
by: deko | last post by:
I'm trying to update the address record of an existing record in my mdb with values from another existing record in the same table. In pseudo code it might look like this: UPDATE tblAddress SET...
3
by: William | last post by:
i am using a dataset and a DataAdapter to update a table with the following schema: ResourceID ProjectID LastName FirstName Year Nov Dec Jan
1
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
8
by: Stephen Plotnick | last post by:
I have three forms and update one table in an Access DB with sucess in one form. In the other two forms I'm trying to do an update to a different table in the Access DB. The error I'm getting...
1
by: ajos | last post by:
hi evrybdy, the problem is:- i had this running before in jsp but when i changed the jsp page using struts tags there occoured a problem... when i enter values in the 2 text boxes and click enter...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.