473,388 Members | 970 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,388 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 1702
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.