jedimaster100
Member
- Joined
- Nov 28, 2008
- Messages
- 7
- Programming Experience
- 3-5
Hi guys! There's something that's been bugging me for a while. I have an application which contains many windows forms and each have one or more connections to the database.
All connections have been made using the Data Source Configuration Wizard which ends up adding three important data objects to a form namely Dataset1, CustomersBindingSource and CustomersTableAdapter (if the source table is Customers). Now in each form I have an update event which goes like this:
--------------------------------------------------------------------------------------
Private Sub updateChanges()
'Try to save changes
Dim changedRecordsTable As System.Data.DataTable = Me.DataSet1.Customers.GetChanges()
Dim changedRecords As Boolean = Not (changedRecordsTable Is Nothing) AndAlso (changedRecordsTable.Rows.Count > 0)
Dim message As String
'Change message if there are changes
If changedRecords = True Then
message = String.Format("You are about to update {0} record(s)." + vbCrLf + "Do you want to continue?", changedRecordsTable.Rows.Count)
Else
'No changes
message = String.Format("Do you want to continue?")
End If
Dim messageReply As System.Windows.Forms.DialogResult = MessageBox.Show(message, Me.Text & " Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
'If reply is yes save changes
If messageReply = Windows.Forms.DialogResult.Yes Then
Try Me.CustomersTableAdapter.Update(Me.DataSet1.Customers)
Catch exc As Exception
End Try
End If
End Sub
--------------------------------------------------------------------------------------
Now this works well however since all my forms have that update subroutine, I was thinking of passing all data objects to a module and all my forms would be calling the module with appropriate parameters only. But I cannot seem to pass CustomersTableAdapter as a parameter. Is there another way to do this?
All connections have been made using the Data Source Configuration Wizard which ends up adding three important data objects to a form namely Dataset1, CustomersBindingSource and CustomersTableAdapter (if the source table is Customers). Now in each form I have an update event which goes like this:
--------------------------------------------------------------------------------------
Private Sub updateChanges()
'Try to save changes
Dim changedRecordsTable As System.Data.DataTable = Me.DataSet1.Customers.GetChanges()
Dim changedRecords As Boolean = Not (changedRecordsTable Is Nothing) AndAlso (changedRecordsTable.Rows.Count > 0)
Dim message As String
'Change message if there are changes
If changedRecords = True Then
message = String.Format("You are about to update {0} record(s)." + vbCrLf + "Do you want to continue?", changedRecordsTable.Rows.Count)
Else
'No changes
message = String.Format("Do you want to continue?")
End If
Dim messageReply As System.Windows.Forms.DialogResult = MessageBox.Show(message, Me.Text & " Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
'If reply is yes save changes
If messageReply = Windows.Forms.DialogResult.Yes Then
Try Me.CustomersTableAdapter.Update(Me.DataSet1.Customers)
Catch exc As Exception
End Try
End If
End Sub
--------------------------------------------------------------------------------------
Now this works well however since all my forms have that update subroutine, I was thinking of passing all data objects to a module and all my forms would be calling the module with appropriate parameters only. But I cannot seem to pass CustomersTableAdapter as a parameter. Is there another way to do this?