I'm trying to fill some columns in a DataTable before sending it to the table adapter for update.
So, I have a databindingSource, a typed Dataset, and a table adapter.
I also have some textboxes on a Windows Forms which fill most of the columns, but some columns not shown need to be added by some calculated values.
I create a new row by calling:
which clears the textboxes so I can start typing.
Then I have a "Save" button with this code:
int index = myDataSet.myTable.Rows.Count;
myDataSet.myTable[index].myColumn = SomeCalculatedValue();
if I debug, I notice that Rows.Count didn't increase after I called the bindingSourceMain.AddNew()
But this code works with other window form and data in which all columns are filled by user.
I also tried this, as suggested in MSDN
MyDataSet.MyTable row = myDataSet.myTable.FindByMyPrimaryKey("hardcoded primary key");
if (row != null)
row.myColumn = SomeCalculatedValue();
For testing, I hardcoded the value of the newly added record, just for testing so, I typed the same value as the "Find" method received.
This always return a null object. It can't find the newly added record.
I must be missing something obviuos.... I'm new on VS/C#.
How do I change column values in the record that is being added?