471,330 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Show DataReader results in DataGridView

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);
}
}
Aug 17 '08 #1
0 1129

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Yasutaka Ito | last post: by
1 post views Thread by Rob via .NET 247 | last post: by
1 post views Thread by John Smith | last post: by
2 posts views Thread by Andrew Robinson | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.