Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating Fields on a new record of a Typed Dataset on form

Posted on 2014-03-04
6
Medium Priority
?
614 Views
Last Modified: 2014-03-05
I have a Win Form using a Strongly Typed Dataset. I have a form that needs to add a new record I have used the 'Bindingsource.addnew' to add a new blank record. I have fields on the Dataset that are not on the form and I need to update them with values before the record is saved. I.e. Audit values and a Foreign Key I know all these values before saving the record. How do you do this? I have tried updating the at record 0 but I get an error saying there is No record 0.
0
Comment
Question by:John_Mason1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 39907712
which control are you using on the form to display data from Data Set?
0
 

Author Comment

by:John_Mason1
ID: 39907760
The controls I am using are Text Boxes. The Dataset is defined in the Dataset designer has a number of fields for example;

SummaryID
RegistrationID
Field1
Field2
DateAdded
AddedBY

The SummaryID is the Primary Key. The RegistrationID is a Foreign Key.

The form is to Display SummaryID, Field1 and Field2. The SummaryID when  bindingsource.addnew'  executes gets -1 in it. These have been dragged onto the form.

I need to be able to update RegistrationID, DateAdded and AddedBY, before the new record is saved. They are not currently on the form surface and I do not want them on the form surface. It seems that the dataset has not been populated with the new record at bindingsource.addnew.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 39907813
You need to commit changes back to the database in your code,  The BindingSource doesn't manage that for you.  It is only responsible for binding the DataSet to the controls.  If you are using something like like an SqlDataAdapter, you will need to use that to write the data back to the database.
0
 

Author Comment

by:John_Mason1
ID: 39907849
Had a feeling you were going to say that.
This means that I have to have the Foreign Key RegistrationID on the form and update the RegistrationID.text property with the Foreign Key as if it is not I get an error message when I 'EndEdit' saying that the RegistrationID can not be null.
I will sort this and if it works I will accept your solution. Thanks
0
 

Author Closing Comment

by:John_Mason1
ID: 39907889
Thank you for the help.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question