Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-03-04
6
Medium Priority
?
618 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
5 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.
Suggested Courses

824 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