tobey1
asked on
Best way to Use Repeatable code
I have this code that I use about 4 times in an application. What is the best way to store it so that I only have to write it once, and access it may times?
Dim sqlcom_str As String = "SELECT * " & _
"FROM Parent_Sequence " & _
"WHERE Sequence = '" & cbox & "' " & _
"ORDER BY Sequence"
' create a data set and fill it
Dim myDataAdapter As New SqlDataAdapter(sqlcom_str, SqlCon_str)
Dim myDataSet As New DataSet
myDataAdapter.Fill(myDataS et, "Parent_Sequence")
' bind the DataSet to the Grid
' SeqDataGrid.DataSource = myDataSet
dg.DataSource = _
myDataSet.Tables("Parent_S equence"). DefaultVie w
' Close Connection
myDataAdapter = Nothing
myDataSet = Nothing
sqlcom_str = Nothing
Dim sqlcom_str As String = "SELECT * " & _
"FROM Parent_Sequence " & _
"WHERE Sequence = '" & cbox & "' " & _
"ORDER BY Sequence"
' create a data set and fill it
Dim myDataAdapter As New SqlDataAdapter(sqlcom_str,
Dim myDataSet As New DataSet
myDataAdapter.Fill(myDataS
' bind the DataSet to the Grid
' SeqDataGrid.DataSource = myDataSet
dg.DataSource = _
myDataSet.Tables("Parent_S
' Close Connection
myDataAdapter = Nothing
myDataSet = Nothing
sqlcom_str = Nothing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It seems that the procedure is somewhat specific and might be best served in the form where it will be used.
However, if you intend to make it more generic and pass in the SELECT statement, then a separate module is fine, but you can easily do that later when you need that.
However, if you intend to make it more generic and pass in the SELECT statement, then a separate module is fine, but you can easily do that later when you need that.
ASKER
It is being used in 1 form on different TabPages.
So was going to Pass the combobox to the Module and then populate the datagrid