VinceC
Member
I have used the Wizard to create a Dataform and connect to an MS Access DB. Within the Dataform code that was automatically generated by the Wizard, can someone tell me where the correct location is to insert a call to a subroutine that I have created that performs calculations on the datagrid. Here is most of the code that the Wizard created:
Thanks, Vince
Code:
Public Sub UpdateDataSet()
Create a new dataset to hold the changes that have been made to the main dataset.
Dim objDataSetChanges As MyProject.MyDataset = New MyProject.MyDataset()
Stop any current edits.
Me.BindingContext(objMyDataset, "tblVBSLInputOutputData").EndCurrentEdit()
Get the changes that have been made to the main dataset.
objDataSetChanges = CType(objMyDataset.GetChanges, MyProject.MyDataset)
Check to see if any changes have been made.
If (Not (objDataSetChanges) Is Nothing) Then
Try
There are changes that need to be made, so attempt to update the datasource by
calling the update method and passing the dataset and any parameters.
Me.UpdateDataSource(objDataSetChanges)
objMyDataset.Merge(objDataSetChanges)
objMyDataset.AcceptChanges()
Catch eUpdate As System.Exception
Add your error handling code here.
Throw eUpdate
End Try
Add your code to check the returned dataset for any errors that may have been
pushed into the row objects error.
End If
End Sub
Public Sub LoadDataSet()
Create a new dataset to hold the records returned from the call to FillDataSet.
A temporary dataset is used because filling the existing dataset would
require the databindings to be rebound.
Dim objDataSetTemp As MyProject.MyDataset
objDataSetTemp = New MyProject.MyDataset()
Try
Attempt to fill the temporary dataset.
Me.FillDataSet(objDataSetTemp)
Catch eFillDataSet As System.Exception
Add your error handling code here.
Throw eFillDataSet
End Try
Try
Empty the old records from the dataset.
objMyDataset.Clear()
Merge the records into the main dataset.
objMyDataset.Merge(objDataSetTemp)
Catch eLoadMerge As System.Exception
Add your error handling code here.
Throw eLoadMerge
End Try
End Sub
Public Sub UpdateDataSource(ByVal ChangedRows As MyProject.MyDataset)
Try
The data source only needs to be updated if there are changes pending.
If (Not (ChangedRows) Is Nothing) Then
Open the connection.
Me.OleDbConnection1.Open()
Attempt to update the data source.
OleDbDataAdapter1.Update(ChangedRows)
End If
Catch updateException As System.Exception
Add your error handling code here.
Throw updateException
Finally
Close the connection whether or not the exception was thrown.
Me.OleDbConnection1.Close()
End Try
End Sub
Public Sub FillDataSet(ByVal dataSet As MyProject.MyDataset)
Turn off constraint checking before the dataset is filled.
This allows the adapters to fill the dataset without concern
for dependencies between the tables.
dataSet.EnforceConstraints = False
Try
Open the connection.
Me.OleDbConnection1.Open()
Attempt to fill the dataset through the OleDbDataAdapter1.
Me.OleDbDataAdapter1.Fill(dataSet)
Catch fillException As System.Exception
Add your error handling code here.
Throw fillException
Finally
Turn constraint checking back on.
dataSet.EnforceConstraints = True
Close the connection whether or not the exception was thrown.
Me.OleDbConnection1.Close()
End Try
End Sub
Thanks, Vince