Hi team, I'm having some issues getting the results of my query to output on a data grid.
I'm using an sql query to get the data from access, which is working fine, but then I want to output it onto a datagrid. My code is as follows just for the file handling part, excuse teh scarppy-ness i'm re-learning this as my end result for the project must be a .exe lol

Dim cn As New OledbConnection()
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Wise-fps01\shared\vbDataBase.mdb"

        Dim command As OleDbCommand = New OleDbCommand("SELECT * FROM marketingDB WHERE company_name =""Opfer Logan"" ", cn)
        command.CommandType = CommandType.Text

        Dim myReader As OleDbDataReader = command.ExecuteReader()

        While myReader.Read()
            'System.Console.Write(" ")
            'System.Console.Write(" ")

        End While

This code just outputs into seperate rows in a list box, which is all i've managed to do so far which as taken me 2 days of re-learning this syntax'y language.

So as you can see im not using sql server or anything just access. So once again, my question is how can you print the result from a query into a datagrid and keep the column names and positions of the columns the same.

If you guys can offer any help, know that it wont go un-appreciated!

I'm assuming that you have a DataGridView on your form, named DataGridView1.

Dim cn As New OledbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Wise-fps01\shared\vbDataBase.mdb")

        Dim adapter As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM marketingDB WHERE company_name = 'Opfer Logan'", cn)

        Dim table As New DataTable()

        DataGridView1.DataSource = table

HAH! EXCELLENT! That never crossed my mind! Nice one mate! Thanks ^ 1000!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.