Here is the scenario:
I have a form that uses a Typed DataSet that contains 9 tables. In my Save routine, I go through each DataTable by name and look at whether items were added or editted and call inserts and updates accordingly. I would prefer to pass this information into a subroutine since it is so repetitive, but how do I pass the name of the insert or edit routine from my InsertData and UpdateData class modules to another routine.
For example, this section of code is the same, just different datatables in use. However, each datatable has a different Insert or Update routine.
VB Code:
If Not ds.Patients.GetChanges(DataRowState.Added) Is Nothing Then iData.InsertPatient(ds.Patients.GetChanges(DataRowState.Added), myTrans) End If If Not ds.Patients.GetChanges(DataRowState.Modified) Is Nothing Then uData.UpdatePatient(ds.Patients.GetChanges(DataRowState.Modified), myTrans) End If
I would like to do something like:
VB Code:
Private Sub SaveData() ' Declarations and other code up here Call CheckForAdditionsAndPost(ds.Patients, myTrans, "InsertPatient") Call CheckForModificationsAndPost(ds.Patients, myTrans, "UpdatePatient") End Sub Private Sub CheckForAdditionsAndPost(ByRef inDataTable as DataTable, ByRef inTrans as SqlTransaction, byval inProcedure as String) Dim iData as New InsertData If Not inDataTable.GetChanges(DataRowState.Added) Is Nothing Then iData. [COLOR=Sienna]Eval(inProcedure).[/COLOR] (inDataTable.GetChanges(DataRowState.Added), inTrans) End If ' Cleanup iData.Dispose() End Sub
Some example code would be greatly appreciated!!




Reply With Quote