Datagridview - saving data
Good morning to everyone.
In VB.net 2008 I would like to have a datagridview in a form.
This datagridview, show the data of one MDB table.
I pretend the user can change data, and save them.
BUT, I DON'T want use the default save button created by the VB in the header of the form.
Cause I have extra code to do in saving moment, I need to create my "save" button.
What code should I enter in the click event of the button???
I've tried many solutions, but none of them works..
Thank You
Re: Datagridview - saving data
Code:
Using con As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=db1.mdb")
con.Open()
cmd = New OleDbCommand("Select * from Table1", con)
Dim da As New OleDbDataAdapter(cmd)
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
End Using
Re: Datagridview - saving data
Tommy,
It wasn't that I needd.
In another forum, answer me and work with:
Me.Validate()
Me.MovBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.ApDataSet)
But now, I have another big problem.
How can I alter a global var, is any valu eof datagridview is changed?
No one of the events works
Re: Datagridview - saving data
It all depends on how the databinding to the datagridview has been setup. If you have bound the datatable directly to the dgv and setup the Insert, Delete & Update sql statements in the dataset designer (note : datatable must have an Index) then the code would be :
Code:
Me.Validate
Me.datatableBindingSource.EndEdit()
Me.datatableTableAdapter.Update(datatable)
So no matter what you do in the dgv the data will be updated. This is the easiest way to handle data in the dgv.
Computerman :)
Re: Datagridview - saving data
Ir works perfectly :)
Thank You :)