2 Replies - 1604 Views - Last Post: 16 October 2016 - 06:00 PM

#1 josef01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 19-March 11

parameterized update query

Posted 13 October 2016 - 09:30 PM

I am getting the selected row in text boxes form datagridview using the below code

 Dim x As Integer
        x = DataGridView1.CurrentCell.RowIndex
        TextBox1.Text = DataGridView1.Rows(x).Cells(0).Value
        TextBox2.Text = DataGridView1.Rows(x).Cells(1).Value
        TextBox3.Text = DataGridView1.Rows(x).Cells(2).Value


I want to update database table with selected row. I am not getting any run time error but it doesnot update table

Try
            Using cnnOLEDB As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\a1.accdb")
                cnnOLEDB.Open()
                Dim cmd As New OleDbCommand("UPDATE Table17 set [email protected], [email protected] WHERE [email protected]", cnnOLEDB)

                cmd.Parameters.AddWithValue("@ID", " &TextBox1.text&")
                cmd.Parameters.AddWithValue("@col1", "&TextBox2.Text&")
                cmd.Parameters.AddWithValue("@col2", "&TextBox3.Text&")
                cmd.ExecuteNonQuery()
                MsgBox("updated.")
                cmd.Dispose()
                cnnOLEDB.Close()


            End Using
        Catch Ex As Exception
            MsgBox(Ex.Message)
        End Try


Is This A Good Question/Topic? 0
  • +

Replies To: parameterized update query

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 5074
  • View blog
  • Posts: 13,697
  • Joined: 18-April 07

Re: parameterized update query

Posted 16 October 2016 - 09:06 AM

What is with the ampersand characters in the values? You should be adding like...

cmd.Parameters.AddWithValue("@col1", TextBox2.Text)



Notice that there is no double quotes around the textbox value (since the Text property returns a string already) and there is no ampersand characters (aka &).

Try setting up the parameters this way. :)
Was This Post Helpful? 0
  • +
  • -

#3 josef01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 19-March 11

Re: parameterized update query

Posted 16 October 2016 - 06:00 PM

Thank you so much, it worked
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1