updating a datagrid that is bound to a dataset

G

Guest

hello,
I have put thisup b4, but I think that people have misunderstood the problem, so I will make it clearer.

I have a problem updating a dataset that is bound to a datagrid.
The code that I use to set up the grid dgsimple to the dataset Mydataset and the table "Orders" is as below (see bottom of page)

My problem is that I can change data in the datagrid on the first row of the grid and the changes will be immediately written away, However If I change data on the 2nd or subsequent rows the data is not written away until you click on the next row of the grid, and you can't expect users to always click on the next row.

What am I doing wrong, Does the bindingcontext have to specify the exact row of the dataset and just defaults to row 0 if none is specifeld. Please help

Geraldine




Private Sub SetupGrid()

'Fill the DataSet

Dim Mycon As SqlConnection = New SqlConnection(strconn)
Dim strquery As String
strquery = "Exec spOrders " & 402
MySqlDataadapter = New SqlDataAdapter(strquery, Mycon)
MyDataset = New DataSet
MySqlDataadapter.FillSchema(MyDataset, SchemaType.Source, "Orders")
MySqlDataadapter.Fill(MyDataset, "Orders")

Mycon = Nothing

End Sub

Private Sub FormatOrdersGrid()
dgsimple.DataSource = MyDataset
dgsimple.DataMember = "Orders"
dgsimple.SetDataBinding(MyDataset, "Orders")

End Sub


Private Sub dgsimple_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgsimple.CurrentCellChanged

DirectCast(BindingContext(MyDataset.Tables!Orders), CurrencyManager).EndCurrentEdit()
Dim objCommandBuilder As New SqlCommandBuilder(Mysqldataadapter)
MySqlDataadapter.Update(MyDataset, "Orders")


End Sub
 
C

Cor

Hi Geraldine,
My problem is that I can change data in the datagrid on the first row of
the grid and the changes will be immediately written away, However If I
change data on the 2nd or subsequent rows the data is not written away until
you click on the next row of the grid, and you can't expect users to always
click on the next row.

I do not understand that your first row is updated while your second not.

The event fires as soon as you click in a new cell or on a new row.
(Not before it or on the top, only real a new cell)
Therefore you do a lot of updates in your program, your dataset is updated
completly everytime when a user clicks another cell or another row.

And you do not do an update when you leave the grid or close the program.

I would choose another event for an update (but I cannot see how frequently
you do want it) and surely check that the update routine also is performed
when you are closing.

To call the event with the clossing you just can do
dgsimple_CurrentCellChanged(nothing, nothing)

I would add miminal this piece of code extra in the program. (To prevent to
much updates)

if myDataset.haschanges then
MySqlDataadapter.Update(MyDataset, "Orders")
end if

I hope this helps something?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top