469,133 Members | 1,203 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

proper method of adding new row to datatable?

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
Dec 6 '05 #1
1 1569
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

"JohnR" <Jo******@hotmail.com> wrote in message
news:FAklf.16619$ad6.2573@trndny08...
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

Dec 7 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ryan McLean | last post: by
3 posts views Thread by Marty McDonald | last post: by
4 posts views Thread by huzz | last post: by
2 posts views Thread by RSH | last post: by
2 posts views Thread by canoewhiteh2o | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.