Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Browse DataReader results in DataGridView

Browse DataReader results in DataGridView

Scheduled Pinned Locked Moved C#
csharpdatabasepostgresqlwinformssysadmin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrusM
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • A AndrusM

      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

      B Offline
      B Offline
      bhadeliaimran 0
      wrote on last edited by
      #2

      you missed DataBind method() ???

      Imran [MCTS] Few have audacity to speak truth

      A 1 Reply Last reply
      0
      • B bhadeliaimran 0

        you missed DataBind method() ???

        Imran [MCTS] Few have audacity to speak truth

        A Offline
        A Offline
        AndrusM
        wrote on last edited by
        #3

        This is Winforms. DataGridView does not have Databind method. If I assign IList<> to DataSource, DataGridView shows data withtout Databind method. So I think I havent missed it.

        Andrus

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups