DataAdapter.Update is not happening. I cannot spot the problem.

  • Thread starter Vassilis Perantzakis
  • Start date
V

Vassilis Perantzakis

This code is for a Pocket PC 2003 application:

When I check for the data by doing a
CustEditDataSet.Tables("Persons").Rows(0)("Tel") and I have changed the
textbox text I get the new value, but it is NOT saved when I call the
SQLCEDataAdapter update method.

Private editQry As String = "select idc,nomiko,Eponymo,Onoma,Tel from
Persons where idc=" + frmCustomers.selectedCust.ToString
Private adoCEDataAdapter As SqlCeDataAdapter
Private CustEditDataSet As DataSet
Private cb As SqlCeCommandBuilder
Private dt As DataTable

Private Sub frmCustEdit_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
adoCEDataAdapter = New SqlCeDataAdapter(editQry, frmConnect.adocon)
cb = New SqlCeCommandBuilder(adoCEDataAdapter)
adoCEDataAdapter.UpdateCommand = cb.GetUpdateCommand
CustEditDataSet = New DataSet
adoCEDataAdapter.Fill(CustEditDataSet, "Persons")
CustEditDataSet.AcceptChanges()
dt = CustEditDataSet.Tables("Persons")
txtSurname.DataBindings.Add(New Binding("Text", dt, "Eponymo"))
txtName.DataBindings.Add(New Binding("Text", dt, "Onoma"))
txtTel.DataBindings.Add(New Binding("Text", dt, "Tel"))
cbLegal.DataBindings.Add(New Binding("SelectedIndex", dt, "nomiko"))
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
adoCEDataAdapter.Update(CustEditDataSet, "Persons")
CustEditDataSet.AcceptChanges()
Me.Close()
End Sub
 
W

W.G. Ryan eMVP

Have you verified the Rowstate and that the Dataset.HasChanges()? If it
doesn't have changes then it won't get sent to the db. BTW, AcceptChanges
is called automatically as the rows are updated so there's no need to call
that after Update.
 
V

Vassilis Perantzakis

Rowstate says it is unchanged and dataset.haschanges returns false. However
I have made changes on the binded textboxes, and when I ask for the value on
the edited field with CustEditDataSet.Tables("Persons").Rows(0)("Tel") I
get the new value. But I don't seem to get it to post.!!!

Shouldn't this code just work? I don't get it.

Thanks
 
J

Jon Skeet [C# MVP]

Vassilis Perantzakis said:
Rowstate says it is unchanged and dataset.haschanges returns false. However
I have made changes on the binded textboxes, and when I ask for the value on
the edited field with CustEditDataSet.Tables("Persons").Rows(0)("Tel") I
get the new value. But I don't seem to get it to post.!!!

Shouldn't this code just work? I don't get it.

Have you called EndEdit?
 

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