Having trouble with a binding source.
Here is the code where ds is the sdataset, bsPhysician is the dataset and dgvPhysician is my datagridview.
Here is the code I have for saving the changes mafe in a datagridview.
This works when I make changes in the datagridview, but I'm concerned about checking the ds instead of the binding source for changes. Not sure if that is the correct wy to do it.
I'm also a little confused because if I use the same code and bind a text box to the binding source like this and make changes in the textbox and not the datagridview, Then it does not recognize that a change was made. ds.HasChanges returns False. The datagridview and textbox are on separate tabs in a tabcontrol and I only let the user make changes to one row at a time.
Also if I bypass the HasChanges code then I get an error when it hits the "ChangedRecordCount =" command. The error is "System.NullReferenceException: Object reference not set to an instance of an object". Confused! Any help will be appreciated. I've tried
but don't know how to get just the rows that changed to use in the dataadapter update.
Auguy
Sylvania/Toledo Ohio
Here is the code where ds is the sdataset, bsPhysician is the dataset and dgvPhysician is my datagridview.
Code:
bsPhysician.DataSource = ds.Tables("dtPhysician")
dgvPhysician.DataSource = bsPhysician
Code:
Dim table As DataTable = ds.Tables("dtPhysician")
Dim dr As DataRow
If Not ds.HasChanges Then
MessageBox.Show("No changes have been made.", _
"Attention", _
MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation, _
MessageBoxDefaultButton.Button1)
Return
End If
Dim changedRecordsTable As DataTable = table.GetChanges()
ChangedRecordCount = changedRecordsTable.Rows.Count
.........
'Rest of code with dtaadapter update
I'm also a little confused because if I use the same code and bind a text box to the binding source like this and make changes in the textbox and not the datagridview, Then it does not recognize that a change was made. ds.HasChanges returns False. The datagridview and textbox are on separate tabs in a tabcontrol and I only let the user make changes to one row at a time.
Code:
txtPatientNbr.DataBindings.Clear()
txtPatientNbr.DataBindings.Add("Text", bsPhysician, "PatientNbr")
txtPatientNbr.MaxLength = 10
Code:
Dim hasChanged As Boolean
hasChanged = DirectCast(bsPhysician.Current, DataRowView).Row.HasVersion(DataRowVersion.Proposed)
Auguy
Sylvania/Toledo Ohio