954,598 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem with update query

Currently using ASP.net 2005
I am havin an errot in update statement my code is:
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand

Dim ssql As String = "UPDATE passwrd SET password ='" + TextBox1.Text + "'where username='" + TextBox2.Text + "'"

myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
& "Data Source=" & Server.MapPath("App_Data\pass.mdb") & ";")
MsgBox(ssql)
myCommand = New OleDb.OleDbCommand(ssql, myConnection)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

Its showing syntax error in UPDATE satement

unknowndevil41
Newbie Poster
12 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

You are having MsgBox(ssql) Can you seen that query and run directly? Or through debugger, set a break point and get value of ssql and post it?

Do you have single quotes as part of data? Does it always fail? Id passwrd a valid table, and other 2 columns Ok?

padtes
Junior Poster in Training
86 posts since Aug 2009
Reputation Points: 53
Solved Threads: 20
 
Dim ssql As String = "UPDATE passwrd SET password ='" + TextBox1.Text + "'where username='" + TextBox2.Text + "'"


an error here is near the where clause. Try inserting a space between ' and where.

Cruize_Invades
Light Poster
40 posts since May 2007
Reputation Points: 6
Solved Threads: 7
 

You are having Can you seen that query and run directly? Or through debugger, set a break point and get value of ssql and post it?

Do you have single quotes as part of data? Does it always fail? Id passwrd a valid table, and other 2 columns Ok?


The update query in ssql variable is ---- UPDATE passwrd set password='1' where username='jay'

unknowndevil41
Newbie Poster
12 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 
Dim ssql As String = "UPDATE passwrd SET password ='" + TextBox1.Text + "'where username='" + TextBox2.Text + "'"

an error here is near the where clause. Try inserting a space between ' and where.


frnd i did try adding space but nothing happen

unknowndevil41
Newbie Poster
12 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

On your original post you are infact missing a space to the left of the WHERE keyword. My suggestions would be to use "&" instead of "+" symbol to concatenate the strings and enclose the table/fieldnames in brackets.

On another note, with regards to:

UPDATE passwrd

Are you sure your TABLE is named passwrd? To clarify, if you had the following:
Table: Person
Fields: password, username

then it should be:

Dim ssql As String = "UPDATE [Person] SET [password] ='" & TextBox1.Text & "' WHERE [username]='" & TextBox2.Text & "'"
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
 

Thnqs frnd problem solved..........
Need to use [] brackets

unknowndevil41
Newbie Poster
12 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

You are welcome!

hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: