Updating Code problem using Sql
Having a problem with my update code for a button to update the password :
Code:
Imports System.Data.SqlClient
Public Class FirstRun
Dim MyConnection As New SqlConnection
Dim MyCommand As New SqlCommand
Dim ra As Integer
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If txtAdminPass.Text = txtAdminPass2.Text Then
MyConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Login.mdf;Integrated Security=True;User Instance=True")
MyConnection.Open()
MyCommand = New SqlCommand("UPDATE UserPass SET Username = '" & txtAdminUser.Text & "', Password = '" & txtAdminPass.Text & "', WHERE ID = '1'", MyConnection)
ra = MyCommand.ExecuteNonQuery()
MsgBox("Your Password Have Been Changed!", MsgBoxStyle.Exclamation)
MyConnection.Close()
Else : MsgBox("The Passwords Do Not Match", MsgBoxStyle.Critical)
End If
End Sub
http://img42.imageshack.us/img42/203/error1yi.png
Re: Updating Code problem using Sql
You have a comma in your SQL right before the WHERE clause which needs to be taken out.
Re: Updating Code problem using Sql
Quote:
Originally Posted by
kevininstructor
You have a comma in your SQL right before the WHERE clause which needs to be taken out.
thanks for that but ive taken it out still have the same error.
Re: Updating Code problem using Sql
The problem is probably due to your field names being reserved words, and as such should not be used as a field/table name (it confuses the query parser within the database system).
If you change the names (in the database and your code), it is likely to work correctly.
For more information (including lists of Reserved words), see the article What names should I NOT use for tables/fields/views/stored procedures/...? from our Database Development FAQs/Tutorials (at the top of the Database Development forum)