Hi all, I am using Visual Studio 2015 with Access 2013 DB (accdb file). I am exploring different ways to interact with the DB and found this video:
C# Application - Insert Delete Update Select in MS Access Database | FoxLearn
https://www.youtube.com/watch?v=uONQaT-nwls
I created a test form with three fields: First and lats name, and email. I added a new data source and followed the video where applicable.
When I click the Save button it saves the data correctly, but only the fields that are bound to the UI elements (text boxes).
Where I am having an issue is saving additional data, such as the name of the data capture person who created this record. I have a CreatedBy text column in the DB, but the name that I assign to it does not save to the DB.
Here is some code:
private void frmTest_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'appDataDataSet.Members' table. You can move, or remove it, as needed.
this.membersTableAdapter.Fill(this.appDataDataSet.Members);
membersBindingSource.DataSource = this.appDataDataSet.Members;
//This indicates that I will capture a new record.
this.appDataDataSet.Members.AddMembersRow(this.appDataDataSet.Members.NewMembersRow());
membersBindingSource.MoveLast();
}
private void button1_Click(object sender, EventArgs e)
{
//Save new record to DB.
try
{
membersBindingSource.EndEdit();
//Assign initials of user that created this record. (Hardcode for test.)
this.appDataDataSet.Members.CreatedByColumn.DefaultValue = "SMD";
//Update with new data in app Data DataSet.
membersTableAdapter.Update(this.appDataDataSet.Members);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
membersBindingSource.ResetBindings(false);
}
}
Except for the public frmTest() routine the above code is all the code I have. Obviously, I am doing something wrong, but I can't determine what. The above code correctly saves the first and last name, and the email, but "ignores" the CreatedBy statement. I am currently looking for information on how to do this. Any orientation would be greatly appreciated! Thanks! Saga