ninjaimp 8 Junior Poster

hi

Im trying to rationalise my code as i feel i am doing the same thing a couple of times with different bits of code.

What i am doing is query a db and putting the result into a dataset and then filling a datagrid with this dataset..Fine. now i have another datagrid which is essentially querying the same db but for data for a day further ahead.

Code at the minute

Private Sub FillToday()
        Dim Searchds As New DataSet
        Dim Searchda As OleDb.OleDbDataAdapter

        sql = ""

        con.Open()
        sql = "SELECT tblStay.ArriveDate, tblStay.Room, tblCustData.CustName FROM tblCustData INNER JOIN tblStay ON tblCustData.CustID = tblStay.CustID WHERE tblStay.ArriveDate = #" & TodaysDate & "#"
        Command = New OleDbCommand(sql, con)
        Command.ExecuteNonQuery()
        Searchda = New OleDb.OleDbDataAdapter(sql, con)
        Searchda.Fill(Searchds)
        dgToday.DataSource = Searchds.Tables(0)
        con.Close()

    End Sub

    Private Sub FillTomorrow()
        Dim Searchds As New DataSet
        Dim Searchda As OleDb.OleDbDataAdapter

        sql = ""

        con.Open()
        sql = "SELECT tblStay.ArriveDate, tblStay.Room, tblCustData.CustName FROM tblCustData INNER JOIN tblStay ON tblCustData.CustID = tblStay.CustID WHERE tblStay.ArriveDate = #" & TomDate & "#"
        Command = New OleDbCommand(sql, con)
        Command.ExecuteNonQuery()
        Searchda = New OleDb.OleDbDataAdapter(sql, con)
        Searchda.Fill(Searchds)
        dgTom.DataSource = Searchds.Tables(0)
        con.Close()

    End Sub

but if i reference the same Dataset within one procedure both datagrids are filled with data from the second search, which of course makes sense but i would like to normalise my code and make it a bit more effiecent!

is there any way i can use a dataset, assign its data to the first datagrid and then re-use it and assign the next one to the second datagrid.

I know this is alot of information, but if anyone could point me in the right direction that would be much appreciated

Regards