DavidT_macktool
Well-known member
How would I make an SQLConnection, SQLDataAdapter, and DataSet available to multiple forms in a project?
My dataset is a Part table of the MackTool database in SQLServer2000
I have a datagrid attached to the dataset on form1(dataform Wizard generated). I need to access form2 which is a textbox layout of the record in focus from the form1 datagrid(dataform Wizard generated). How do I set the databindings of form2 to the dataset on form1? I also want to share the add, update, and delete functions of the dataset between the two forms so that updates made on either form are maintained and displayed on the other form. I need to have the Datagrid component of form1 automatically refresh to display the updates made on form2 when form 2 is closed.
Is there a way to have the dataform wizard generate the code for me and convert the form into a public business class that the dataset and dataset add, update, and delete functions can be called from both forms?
I have tried this functionality with a connection, dataadapter and dataset residing on form1 and the referenced dataset residing on form2.
I databind the text boxes of form2 to the referenced dataset on form2 and pass the record location from form1 to form2 when opened. Form 2 correctly displays the desired record but any updates made on form 2 are not passed back to form1. Form1 and form2 both have instances of the load and update functions generated by the dataform wizard
sample:
Public Function UpdateDataSet()
'Create a new dataset to hold the changes that have been made to the main
ataset.
Dim objDataSetChanges As Mack.dsPart = New Mack.dsPart
Dim objDataSetUpdated As System.Data.DataSet = New Mack.dsPart
'Get the changes that have been made to the main dataset.
objDataSetChanges = CType(pds.GetChanges, Mack.dsPart)
'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.
objDataSetUpdated = pds.Clone
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 object's error.
Try
pds.Merge(objDataSetUpdated)
Catch eUpdateMerge As System.Exception
'Add exception handling code here
Throw eUpdateMerge
End Try
'Commit the changes that were just merged
'This moves any rows marked as updated, inserted or changed to being marked as original values
pds.AcceptChanges()
End If
End Function
What can I do to create a class or module to hold the dataset and dataset functions and call them from any form in the project. A centralized location for loading the dataset and updating the database is what I want.
There should be a sample database application that has a display form and an edit form for a sqlServer2000 table, where is it?
Am I stupid? Is this a common function when dealing with database tables? What am I not getting here, some underlying principle? Seems like a few lines of code should do it.
HELP!
My dataset is a Part table of the MackTool database in SQLServer2000
I have a datagrid attached to the dataset on form1(dataform Wizard generated). I need to access form2 which is a textbox layout of the record in focus from the form1 datagrid(dataform Wizard generated). How do I set the databindings of form2 to the dataset on form1? I also want to share the add, update, and delete functions of the dataset between the two forms so that updates made on either form are maintained and displayed on the other form. I need to have the Datagrid component of form1 automatically refresh to display the updates made on form2 when form 2 is closed.
Is there a way to have the dataform wizard generate the code for me and convert the form into a public business class that the dataset and dataset add, update, and delete functions can be called from both forms?
I have tried this functionality with a connection, dataadapter and dataset residing on form1 and the referenced dataset residing on form2.
I databind the text boxes of form2 to the referenced dataset on form2 and pass the record location from form1 to form2 when opened. Form 2 correctly displays the desired record but any updates made on form 2 are not passed back to form1. Form1 and form2 both have instances of the load and update functions generated by the dataform wizard
sample:
Public Function UpdateDataSet()
'Create a new dataset to hold the changes that have been made to the main
ataset.
Dim objDataSetChanges As Mack.dsPart = New Mack.dsPart
Dim objDataSetUpdated As System.Data.DataSet = New Mack.dsPart
'Get the changes that have been made to the main dataset.
objDataSetChanges = CType(pds.GetChanges, Mack.dsPart)
'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.
objDataSetUpdated = pds.Clone
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 object's error.
Try
pds.Merge(objDataSetUpdated)
Catch eUpdateMerge As System.Exception
'Add exception handling code here
Throw eUpdateMerge
End Try
'Commit the changes that were just merged
'This moves any rows marked as updated, inserted or changed to being marked as original values
pds.AcceptChanges()
End If
End Function
What can I do to create a class or module to hold the dataset and dataset functions and call them from any form in the project. A centralized location for loading the dataset and updating the database is what I want.
There should be a sample database application that has a display form and an edit form for a sqlServer2000 table, where is it?
Am I stupid? Is this a common function when dealing with database tables? What am I not getting here, some underlying principle? Seems like a few lines of code should do it.
HELP!