Results 1 to 4 of 4

Thread: Updating Code problem using Sql

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    21

    Exclamation 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

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,527

    Re: Updating Code problem using Sql

    You have a comma in your SQL right before the WHERE clause which needs to be taken out.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    21

    Re: Updating Code problem using Sql

    Quote Originally Posted by kevininstructor View Post
    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.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,429

    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)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width