Solved

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

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
This video teaches viewers about errors in exception handling.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

617 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