Link to home
Start Free TrialLog in
Avatar of tobey1
tobey1Flag for United States of America

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(myDataSet, "Parent_Sequence")

        ' bind the DataSet to the Grid
        ' SeqDataGrid.DataSource = myDataSet
        dg.DataSource = _
            myDataSet.Tables("Parent_Sequence").DefaultView

        ' Close Connection
        myDataAdapter = Nothing
        myDataSet = Nothing
        sqlcom_str = Nothing
ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tobey1

ASKER

I was going to add it to a Module and then call it in from there.

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
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.