Problem when updating data RRS feed

  • Question

  • I restored the cell data from the DataGridVIEW to the TextBox but when I save the changes nothing appears

    Dim con As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\web_database.accdb;Jet OLEDB:Database Password=12345")

    Sub updat() con.Open()

    Dim cmd As New OleDbCommand("update web_tb set name_web=@name_web where ID_web=@ID_web", con) cmd.Parameters.AddWithValue("@name_web", TextBox1.Text) cmd.ExecuteNonQuery() con.Close() Validate() DataGridView1.Refresh() BindingSource1.EndEdit() DataAdapter1.Update(DataSet1, "web_tb") DataSet1.AcceptChanges() If con.State = ConnectionState.Open Then con.Close() End If con.Dispose() MsgBox("UPDATE DONE") End Sub

    Tuesday, December 12, 2017 6:49 PM


  • Declare a variable for ExecuteNonQuery e.g. Dim Result As Integer = cmd.ExecuteNonQuery(), my guess is you expect one row to be updated thus Result should be 1, if not 1, -1 means it failed, over 1 means too many records were affected.

    Of course before running ExecuteNonQuery do If DataSet1.HasChanges ...

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by ahmeddc Tuesday, December 12, 2017 11:42 PM
    Tuesday, December 12, 2017 10:25 PM