1 Replies - 1253 Views - Last Post: 07 December 2012 - 10:46 AM Rate Topic: -----

#1 pratik65  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 10-September 12

i am getting an syntax error in Update Command i am stuck

Posted 07 December 2012 - 09:58 AM

i am getting an Syntax Error in Update Command I dont know why
i am using ms access2010 as my back end and Vb.net as my front End

my Code for Update is :
 Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
        Dim query As String
        Try

            query = "UPDATE Customer_Master SET Names = '" & txtname.Text & "', Address='" & txtaddr.Text & "', PhoneNo='" & txtphno.Text & "'  WHERE CustomerID= '" & txtcid.Text & "'"
            cmd.Parameters.AddWithValue("@Names", (txtname.Text))
            cmd.Parameters.AddWithValue("@Address", (txtaddr.Text))
            cmd.Parameters.AddWithValue("@PhoneNo", (txtphno.Text))
            conn.Open()
            cmd = New OleDb.OleDbCommand(query, conn)
       
            cmd.ExecuteNonQuery()

            MsgBox(txtcid.Text = "Record updated.")
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString())
        Finally
            If conn.State = ConnectionState.Open Then
                conn.Close()
            End If
        End Try
        'cmd.Dispose()

    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: i am getting an syntax error in Update Command i am stuck

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5466
  • View blog
  • Posts: 11,742
  • Joined: 02-June 10

Re: i am getting an syntax error in Update Command i am stuck

Posted 07 December 2012 - 10:46 AM

yeah, your query is all sorts of fraked up.

You don't try to inject the values by building a string (line 5) *AND* try to include those same values as parameters.

Q:... how to do x,y,z with a database {probably for the first time}...
A: Read this tutorial
Entire section of tutorials
Parameterizing Your SQL Queries: The RIGHT Way To Query A Database.
Using SqlDependency to monitor SQL database changes
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1