LuckyLuke82
LuckyLuke82

Reputation: 604

VB.NET - Save changes in Datagridview to DB

I have set Oracle connection to DatagridView, via manager. Line for this is:

  Me.UsersTableAdapter.Fill(Me.MyDataSet._Users)

Now I want to save all changes made in Datagridview to DB. Tried this but not working:

 Me.UsersTableAdapter.Update(Me.MyDataSet._Users)

What am I missing here ?

Upvotes: 0

Views: 1294

Answers (2)

The scion
The scion

Reputation: 972

1.Maybe you are missing validate() and endEdit() ?

Try
    Me.Validate()
    Me.UsersBindingSource.EndEdit()
    Me.UsersTableAdapter.Update(Me.MyDataSet._Users)
    MsgBox("Update successful")

Catch ex As Exception
    MsgBox("Update failed")
End Try
  1. Do you have primary key for the table?

Update

Fix the code I present -

Me.UsersBindingSource.EndEdit()

link

Upvotes: 1

LuckyLuke82
LuckyLuke82

Reputation: 604

Solved. Correct synthax is:

Try
    Me.Validate()
    Me.UsersBindingSource.EndEdit()
    Me.UsersTableAdapter.Update(Me.MyDataSet._Users)
    MsgBox("Update successful")

Catch ex As Exception
    MsgBox("Update failed")
End Try

@the scion, thanks !!

Upvotes: 0

Related Questions