Solved

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

Posted on 2014-03-04
6
594 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
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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

837 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