Problem with saving data into mdb

sheki

New member
Joined
Feb 8, 2010
Messages
1
Programming Experience
Beginner
Hi,

I'm trying to save data from Dataset to mdb file. If I use BindingNavigator for inserting row, saving in mdb,.. everything works perfect (this is the autogenerated form which is made only with drag and drop).

Until now I programaticaly managed to insert vales into new row (cells) but I can't update mdb file - TableAdapter sucessfully.

Code:

Dim novaUsageVrsta As DataRow = Ds.Tables("tbl_usage").NewRow()

'here I'm adding rows
novaUsageVrsta(1) = Now.ToString("d")
novaUsageVrsta(2) = CurrentActiveWindow.Zacetek
novaUsageVrsta(3) = CurrentActiveWindow.Konec
'novaUsageVrsta(4) = CurrentActiveWindow.Trajanje
novaUsageVrsta(5) = UCase(CurrentActiveWindow.Proces)
novaUsageVrsta(6) = Environment.UserName

'Here could be a problem
Ds.tbl_usage.Rows.Add(novaUsageVrsta)
Ds.tbl_usage.AcceptChanges()

Me.Validate()
Me.Tbl_usageBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Ds)

And here is autogenerated code which works perfectly
How does BindingNavigator:
Private Sub Tbl_usageBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tbl_usageBindingNavigatorSaveItem.Click
Me.Validate()
Me.Tbl_usageBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Ds)

End Sub


So my problem is only that that I don't know how to isert new rows with values. :confused:

Thanks for help!
 
When you call this:

Ds.tbl_usage.AcceptChanges()

It will mark all the rows in your table as having RowState "unchanged"
And when the TableAdapter goes through the table, ignoring rows that are Unchanged, and looking for rows that are Added (to call insert) or Modified (to call update) or Deleted (to call delete)..

..this is why your insert never gets called :)
 
Back
Top