Reputation: 2719
I have this code :
DataRow myNewRow;
myNewRow = hRAddNewDataSet.Vication.NewRow();
myNewRow["EmployeeID"] = Convert.ToInt32(employeeIDTextBox.Text);
myNewRow["VicationDate"] = vicationDateDateTimePicker.Value;
myNewRow["VicationSubject"] = vicationSubjectTextBox.Text;
myNewRow["VicationType"] = Convert.ToInt32(vicationTypeComboBox.SelectedValue);
myNewRow["Time"] = Convert.ToInt32(timeTextBox.Text);
myNewRow["VicationAs"] = Convert.ToInt32(vicationAsComboBox.SelectedValue);
myNewRow["StatementNo"] = statementNoTextBox.Text;
myNewRow["StatementDate"] = statementDateDateTimePicker.Value;
myNewRow["Info"] = infoTextBox.Text;
hRAddNewDataSet.Vication.Rows.Add(myNewRow);
When I run this code, it will add new row as I want but it will also update the current row depends on the value of
vicationBindingSource.Position
How I can solve this problem?
Upvotes: 0
Views: 9389
Reputation: 10257
since there is a databinding all your changes to the bound properties of the controls will be written to the datasource (normally after successful validation of the control)
so when you enter the values of you new row, you are actually changing the values of the current row first
you should add your row by using the AddNew()
method of your BindingSource
Upvotes: 1