proper method of adding new row to datatable?

  • Thread starter Thread starter JohnR
  • Start date Start date
J

JohnR

I'm using oledb to an Access datatable. I load the table into a dataset. I
create databindings to link the fields on my form to the corresponding
fields in the datatable. The tables DefaultView.Sort is set to the field
that is bound to a dropdown (where I can pick what record to view, and the
dropdown list is sorted). I click a rec in the dropdown, and all the values
of that record then populate the fields on my form. Editing, and deleting
existing records all work fine. However if I create a newrow, scan each
column to eliminate dbNull values, then add that row to the datatable, the
databinding.position does not point to the new record. Question is what is
the best way to position to the newly added record so I can enter values?
I've tried a couple of things but I think I'm getting bogged down and making
it too complicated. I'm sure there is an easy way that I'm just not
thinking of (remember the DefaultView.sort is set to a field and I think
that may be complicating matters).
Thanks,
John
 
I just realized that a couple of things were in play... first I stopped
resorting the data after the add of the new record - that seemed to screw
things up. Second I now do a bindingcontext.endcurrentedit to push the data
from the bound fields back to the dataset. By not doing that the table
constraints 'caught' the face that, if I added 2 records one after the
other, they both had blank primary keys (they really didn't, but since I
didn't do a 'endcurrentedit' the real values were not pushed to the table in
the dataset).

John
 

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

Back
Top