#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Help with update query


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

    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
    Code:
    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 col1=@col1, col2=@col2 WHERE ID=@ID", 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
  2. #2
  3. Gratefully Deadicated
    ASP Adventurer (500 - 999 posts)

    Join Date
    Sep 2006
    Location
    The Great Machine
    Posts
    518
    Rep Power
    356
    Remove the quotes and & from your code:
    Code:
                    cmd.Parameters.AddWithValue("@ID", TextBox1.text)
                    cmd.Parameters.AddWithValue("@col1", TextBox2.Text)
                    cmd.Parameters.AddWithValue("@col2", TextBox3.Text)
                    cmd.ExecuteNonQuery()
    Last edited by Zath; January 19th, 2017 at 08:45 AM.

Similar Threads

  1. Update query join tables and update field
    By pschneider in forum SQL Development
    Replies: 1
    Last Post: February 22nd, 2008, 01:09 PM
  2. Using Update Query to update values
    By SHAWTY721 in forum Microsoft Access Help
    Replies: 1
    Last Post: October 3rd, 2007, 10:25 AM
  3. Replies: 7
    Last Post: December 9th, 2004, 08:36 PM
  4. HELP WITH UPDATE QUERY - "Operation must use an updateable query!"
    By dmoonme in forum Microsoft Access Help
    Replies: 0
    Last Post: September 22nd, 2004, 02:29 PM
  5. Update an Autolookup field with Update Query
    By Zowy80 in forum Microsoft Access Help
    Replies: 11
    Last Post: May 26th, 2004, 08:16 PM

IMN logo majestic logo threadwatch logo seochat tools logo