473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1703
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: DraguVaso | last post by:
Hi, I have a ComboBox of +- 15.000 items in it, via a DataSource. On Top of the Items-list, I want to add some values, based on a user choise (via a filter on the DataSource). Does anybody know...
1
by: Ryan McLean | last post by:
Hi everyone! What is happening is the method: sub_btnSubmitClicked is being executed every time any other object with a Handler is executed. I am trying not to use the withevents and handles...
3
by: Marty McDonald | last post by:
I have <asp:Table... </asp:Table> on my webform. In codebehind, I populate a DataTable whose data should appear in the asp:Table. I created my own code to populate the asp:Table with the...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: psb | last post by:
I thought this was weird?? is this a bug in framework 1.0??? (1.0 is the version I am running against) --------------------------- dim dtAll as new datatable dim dtTmp as datatable dtTmp =...
4
by: huzz | last post by:
I have a mothod in a class that return a datareader object as show below and trying to assign the datareader object to a datagrid but getting this error message: CS0120: An object reference is...
2
by: RSH | last post by:
I am trying really hard to grasp the concept of Interfaces and their real world usage. I constructed a simple project of a webpage that contains two controls. I am enabling communication back...
2
by: canoewhiteh2o | last post by:
I am having trouble adding data columns to a disconnected database. I first load a datatable using: private DataTable dtMacros = new DataTable(); private ArrayList macro = new ArrayList();...
3
by: jehugaleahsa | last post by:
Hello: I am binding a DataGridView with a BindingList<T>, where T is a custom business object that implements INotifyPropertyChanged. When you bind a DataGridView to a DataTable, it has this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.