Data Entry Form

G

Guest

Background:
I have a data entry form that is bound to a DataSet. This DataSet contains
9 tables and the form displays data from each table in textboxes, not a
DataGrid. One of the tables in the ParentTable and the rest are children.

For Example:
The form shows the Customer and their most recently added Contact (in
textboxes, not in a DataGrid). When I click the Add button on the form, I
enumerate through all of the DataTables in the DataSet and call
BindingContext(DataTable).AddNew(). (Now, make note that the end user may
not always decide to enter a contact's information.) (For this example,
assume that the user did not enter a contact.) When the user clicks on Save,
I again enumerate through all of the DataTables in the DataSet and call
BindingContext(DataTable).EndCurrentEdit(). At this point every table in the
DataSet shows as having 1 row. When really the row for the Contacts table is
blank. This creates problems when trying to insert the data into the
database.

Is there a better way of doing this? I know that I could watch for entry
into any of the fields for the Contacts table and then call AddNew, but that
would be cumbersome to code.

PS - I know that the best way to do this would be to have a button that the
user clicks on to "Add New Contact" and then display a dialog form that would
allow the end user to enter the nessary information, or even just enable the
controls on the main form. That is the best and easiest way to accomplish
what I need to accomplish, however, my client wants it done the way described
above. They are moving from a DOS-based DBase application and want this to
act as much like the old app as possible.

Thanks in advance!!
 
G

Guest

Cor,

Thanks for the reply. My example appears to have been lacking some
important information. Let me see if I can elaborate.

For ease, let's just consider a form that uses a DataSet that contains 2
tables named Customers and Contacts. The Contacts table can contain multiple
records for each Customer. On the form, I have a groupbox with information
about the customer and another groupbox with information about the last
contact created. The only buttons on the form are a New and Save button.
The New button creates a new customer (which in turn creates a new contact)
and the Save button saves the data. When the user clicks on the New button,
I do not know at that point whether they are going to enter a Contact or not,
so I call BindingContext(ds.Customers).AddNew() and
BindingContext(ds.Contacts).AddNew(). Assuming that the user entered data
for the customer, but not for the contact, when the user clicks Save, I need
a way to determine if information was entered for the contact section.

I know that I can loop through each field in ds.Contacts and determine if
any of them have values other than the defaults, but there has to be an
easier way.

If you have a better way of going about this, please let me know.

Again, thanks.
 
C

Cor Ligthert [MVP]

ASPNOT,

Did you try the sample, if you use that for both your customers and your
contacts than you get in my idea a nicer application with much less work.

Your contacts should than have in the rowfilter of the defaultview the id of
the customer.,

In your case I would just use the sample. It is so easy to try and probably
is changing your program than almost no work.

I hope this helps,

Cor
 
G

Guest

I looked at the example on your site and that uses navigation buttons to move
around and to add a new record. That would be far too easy for this client.
They do not want to have to click a button to add a Contact. They want to
click the Add New button for the Customer and have it automatically set them
up with a blank Contact. Then they want to let the application determine
whether they typed anything into the Contact or not.

I am currently working on some code to loop through each DataTable in the
DataSet and then each DataRow in the DataTable and then through each
DataColumn in each DataRow to compare the values to the Default values to see
if any changes have been made to the data for the Contacts table. I find
this way of doing it to be very cumbersome. There has to be a better way. I
have run into an issue with this mechanism that if I RejectChanges() on a
DataRow, then I can no longer enumerate through the DataRows since the
collection has now changed.
 

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

Top