Syntax error in update statement

Posted by Rrana under VB.NET on 7/19/2012 | Points: 10 | Views : 6065 | Status : [Member] | Replies : 9
Hi all,

I am using windows application with ms-access DB
When i am trying to update the query it shows error as syntax error in update statement

Code is:------------

cmd.CommandText = "UPDATE Wsr_UserDetails SET Password='" & txtnpwd.Text & "',Confirm_Password='" & txtcpwd.Text & "',First_Login =1 WHERE UserId =" & UserId

cmd.CommandType = CommandType.Text
cmd.Connection = con
cmd.ExecuteNonQuery()-------------> Getting error here

Thanks in Advance

Sucharitha Goud
Bank Of America..



Responses

Posted by: GSM_GSV on: 7/19/2012 [Member] Starter | Points: 25

Up
0
Down
I think you have missed quotation marks somewhere, may be at the end

Also, let me know the error details.

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rrana on: 7/19/2012 [Member] Starter | Points: 25

Up
0
Down
It shows error as syntax error in update statement



Sucharitha Goud
Bank Of America..

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 7/19/2012 [Member] Starter | Points: 25

Up
0
Down
UPDATE Wsr_UserDetails SET Password='" & txtnpwd.Text & "',Confirm_Password='" & txtcpwd.Text & "',First_Login =1 WHERE UserId =" & UserId "

____________
www.flickr.com/photos/psdesigner/

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: GSM_GSV on: 7/19/2012 [Member] Starter | Points: 25

Up
0
Down
try this

"UPDATE Wsr_UserDetails SET Password='" & txtnpwd.Text & "',Confirm_Password='" & txtcpwd.Text & "',First_Login =1 WHERE UserId ='" & UserId & "'"

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/19/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
cmd.CommandText = "UPDATE Wsr_UserDetails SET Password='" & txtnpwd.Text & "',Confirm_Password='" & txtcpwd.Text & "',First_Login =1 WHERE UserId =" & UserId

cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()


Note: Check your DataType or share ur Table Structure with datatype

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rrana on: 7/20/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Everyone,

Password is a reserved work,so i have changed the colums name as PWD

No its working fine,but not updated in Database.

**************
con.Open()
cmd = New OleDbCommand("UPDATE Wsr_UserDetails SET PWD='" & txtnpwd.Text & "',First_Login =1 WHERE UserId=" & lbluid & ";", con)
cmd.ExecuteNonQuery()
con.Close()


Sucharitha Goud
Bank Of America..

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/20/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this

 

con.Open()
cmd = New OleDbCommand( ("UPDATE Wsr_UserDetails SET PWD='" & txtnpwd.Text & "',First_Login =1 WHERE UserId=" & lbluid, con)
cmd.ExecuteNonQuery()
con.Close()


Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raghumv on: 7/20/2012 [Member] Starter | Points: 25

Up
0
Down
SqlConnection sqlcon = new SqlConnection(GetConnectionString());

SqlCommand cmdResposnse = new SqlCommand("UPDATE frm_category SET Password='" + txtnpwd.Text + "',Confirm_Password='" +txtcpwd.Text + "',First_Login =1 WHERE UserId =" + UserId ",sqlcon );
sqlcon.Open();
cmdResposnse.ExecuteNonQuery();
sqlcon.Close();


u didn't sqlconnection open. thats the problem

Raghu.M.V.
Software Engineer.

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 7/20/2012 [Member] Starter | Points: 25

Up
0
Down
Rrana,

Can you give me the actual SQL code that you are getting just before the code gets executed. i mean the query, Only The Query with all the parameters filled.

____________
www.flickr.com/photos/psdesigner/

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response