473,836 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sor t 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.pos ition 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.sor t is set to a field and I think
that may be complicating matters).
Thanks,
John
Dec 6 '05 #1
1 1721
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******@hotma il.com> wrote in message
news:FAklf.1661 9$ad6.2573@trnd ny08...
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.Sor t 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.pos ition 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.sor t 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
3152
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 how I can do this? When just adding them with ComboBox.items.Insert I get an "Items collection cannot be modified when the DataSource property is set". Does anybody has a solution for this? i'm surely not the first to do this :-) I'm using...
1
1898
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 method of adding handles to objects (I think that is where my problem lies) . . . sorry for the long post here is my codebehind and .aspx code. Thank you for any assistance anyone can offer! Ryan Public Class registration_report
3
12025
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 DataTable, then I discovered the asp:Table has a DataBind method. But the method takes no args and so I'm confused how to use it. Is there a link to see how DataBind works for asp:Table? Should I just use my own code anyway? Thanks... Here's my...
3
1958
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 example would be: Let's say Column1=StartDate and Column2=EndDate. In addition to displaying Column1 and Column2, I need to do some calculations and display in as Column3. The calculations are easy and can be done in the code-behind. How to display...
1
1587
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 = LoadDataTable("select top 100 from table...") for i=0 to dtTmp.rows.count -1 ''''ERROR ON THIS LINE''' dtAll.Rows.Add(dtTmp.rows(i))
4
278
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 required for the nonstatic field, method, or property 'intranet.discussion.discussion.GetThreads(int)' public SqlDataReader GetThreads(int TopicID) {
2
1289
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 and forth between the page as well as controls. I used two interfaces to remove the hardcoded references. Is what I'm doing correct? Any suggestions? Thanks!
2
3374
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(); private SQLiteConnection cn; private SQLiteDataAdapter adapterMacros; cn = new SQLiteConnection("Data Source = irDatabase.db3"); SQLiteCommand commandMacros = new SQLiteCommand(); commandMacros.CommandText = "SELECT * FROM irMacros"; adapterMacros =...
3
9703
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 cool little feature - it will not call DataTable.Rows.Add until after you leave the DataGridView row. This is cool because it lets your user edit the record as much as needed to get it into a valid state before actually adding it to the DataTable.
0
9812
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10828
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10534
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10579
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10244
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9364
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7775
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4444
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.