Underlying data not being updated.

  • Thread starter Thread starter foo
  • Start date Start date
F

foo

Hello,

My underlying data are not being updated. The rows in the dataset are
updated but when I close the app, the table (Access 2000) is unchanged. I
can read all the rows with no problem and navigate through them. The code
does not throw any errors - I had to trim it a little to put it into this
message, but this is the way it's trying to work.

dim daForm As System.Data.OleDb.OleDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter( )
dim dsForm As DataSet = New DataSet( )
dim pk(0) As DataColumn

dim myTable as string
dim mySubject as string
myTable = "tTemplate"
mySubject = "Template"

daForm.SelectCommand = New System.Data.OleDb.OleDbCommand(formSQL,
gSharedDataCon)
daForm.Fill(dsForm, myTable)
pk(0) = dsForm.Tables(myTable).Columns("TemplateID")
dsForm.Tables(myTable).PrimaryKey = pk

dsForm.Tables(myTable).Rows(0).BeginEdit()
dsForm.Tables(myTable).Rows(0)(mySubject) = "TEST"
dsForm.Tables(myTable).Rows(0).EndEdit()
dsForm.Tables(myTable).AcceptChanges()

Thanks,

Bill
Cincinnati, OH USA
 
Hi Foo,

Have a look at
OleDbDataAdpater.Update

And do something as
dsForm.Tables(myTable).Rows(0).BeginEdit()
dsForm.Tables(myTable).Rows(0)(mySubject) = "TEST"
dsForm.Tables(myTable).Rows(0).EndEdit()

daForm.update(dsForm, myTable)

or as i find better

if dsForm.haschanges then
daForm.update(dsForm.getchanges, myTable)
end if
dsForm.Tables(myTable).AcceptChanges()
I hope this helps?

Cor
 
Hi,

You should call DataAdapter.Update method to store data to database.
The dataset is always disconnected.
See
Database Updates from Datasets
..net help topic.
 
That didn't work. Do I need to provide an UpdateCommand object before I call
DataAdapter.Update( ) ?
 
That didn't help. Do I need to provide an UpdateCommand object before I call
DataAdapter.Update( ) ?
 
I tried this and when dsForm.HasChanges is checked it's false and the
dfForm.Update( ) is never executed. I'm confused. :(
 
Hi Foo,
I saw your other message one addition (it has not to do with the
haschanges),
so you was not yet there, but would have given an error

When "if haschanges" does not work, send your code again about that changed
part, till the end.

dim cmb as new oledbCommandbuilder(daForm)
 
Back
Top