Show DataReader results in DataGridView

A

Andrus

I need to view DataReader results for quick debug.
I tried code below but DataGridView is empty.

How to fix ?

Andrus.

using System.Data;
using System.Windows.Forms;
using Npgsql;

class Form1 : Form
{
static void Main()
{
Application.Run(new Form1());
}

DataGridView dataGridView1 = new DataGridView();

Form1()
{
string s = "SERVER=localhost;USER=postgres";
string query = @"select * from pg_tables";
var con1 = new NpgsqlConnection(s);
IDbCommand cmd = con1.CreateCommand();
cmd.CommandText = query;
con1.Open();
var dr = cmd.ExecuteReader();
dataGridView1.DataSource = dr;
Controls.Add(this.dataGridView1);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top