Browse DataReader results in DataGridView
C#
3
Posts
2
Posters
0
Views
1
Watching
-
I need to view DataReader results in WinForms application for quick debug. I tried code below but DataGridView is empty. How to fix ?
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); }
}
Andrus
-
I need to view DataReader results in WinForms application for quick debug. I tried code below but DataGridView is empty. How to fix ?
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); }
}
Andrus
you missed DataBind method() ???
Imran [MCTS] Few have audacity to speak truth
-
you missed DataBind method() ???
Imran [MCTS] Few have audacity to speak truth