Solved

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

Posted on 2014-03-04
6
574 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
  • 3
6 Comments
 
LVL 16

Expert Comment

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

Author Comment

by:John_Mason1
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for the help.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now