Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15168

How to Fill multiple datagrid

$
0
0
Trying to wrap my head around vb6 -> .net
What do I need to change to fill 3 datagridviews with different data?
I populate the grids during startup and refer to them at various points in the program (to reduce database calls)
I can obviously populate them individually with 3 separate calls, but want to do it with one. How do I clear the fill(dt) to move onto the next one (as currently it populates each with the first data)

Code:


            Dim sql As String
            Dim cmd As New OleDb.OleDbCommand
            Dim dt As New DataTable
            Dim da As New OleDb.OleDbDataAdapter
            con.Open()

            sql = "First SQL String."
            cmd.Connection = con
            cmd.CommandText = sql
            da.SelectCommand = cmd
            da.Fill(dt)
            DataGridOne.DataSource = dt
'This doesnt work
            'dt.clear

            sql = "Second SQL String"
            cmd.Connection = con
            cmd.CommandText = sql
            da.SelectCommand = cmd
            da.Fill(dt)
            DataGridTwo.DataSource = dt

            sql = "Third SQL String"
            cmd.Connection = con
            cmd.CommandText = sql
            da.SelectCommand = cmd
            da.Fill(dt)
            DataGridThree.DataSource = dt


Viewing all articles
Browse latest Browse all 15168


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>