PgSqlDataTable not available for ASP.NET?

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
ericdes
Posts: 8
Joined: Thu 03 Apr 2008 09:15

PgSqlDataTable not available for ASP.NET?

Post by ericdes » Wed 24 Dec 2008 06:33

Only the component PgSqlDataSource gets displayed in in the VS 2008 toolbox when I'm in an ASP.NET web application.

Is there a way to use a PgSqlDataTable? I would like to link a grid with a PostgreSql table without having to write the SQL plumbing code...javascript:emoticon(':?')

Thank you,
Eric.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Wed 24 Dec 2008 09:16

PgSqlDataSource is the only component that is available in design time in an ASP.NET web application. But you can use the PgSqlDataTable component in run-time:

Code: Select all

using (PgSqlConnection connection = new PgSqlConnection("host=localhost; database=postgres; user id=postgres; password=***")) {
        connection.Open();
        PgSqlCommand command = new PgSqlCommand("Select * from emp;", connection);
        PgSqlDataTable table = new PgSqlDataTable(command);
        table.Open();
        GridView1.DataSource = table;
        GridView1.DataBind();
      }

ericdes
Posts: 8
Joined: Thu 03 Apr 2008 09:15

Post by ericdes » Thu 25 Dec 2008 17:04

I tried your code which runs without any errors but doesn't return any rows:

Code: Select all

            using (PgSqlConnection connection = new PgSqlConnection(pgsqlConnectionString))
            {
                connection.Open();
                PgSqlCommand command = new PgSqlCommand(@"Select * from trailers.""Reservation""", connection);
                PgSqlDataTable table = new PgSqlDataTable(command);
                table.Open();
                foreach (System.Data.DataRow myRow in table.Rows)
                {
// No rows!!! Although the table is not empty.
                } 
                this.schedulerControl.AppointmentDataSource = table;
                this.schedulerControl.AppointmentDataSourceID = null;
                this.schedulerControl.DataBind();
            }

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 26 Dec 2008 09:39

If you want to use the DataRow collection of the PgSqlDataTable component in run-time, it is necessary to set its FetchAll property to true before calling the Open() method. Please try using the following code:

Code: Select all

...
PgSqlDataTable table = new PgSqlDataTable(command);
table.FetchAll = true;
table.Open();
...

Post Reply