Page 1 of 1

PgSqlDataTable not available for ASP.NET?

Posted: Wed 24 Dec 2008 06:33
by ericdes
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.

Posted: Wed 24 Dec 2008 09:16
by Shalex
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();
      }

Posted: Thu 25 Dec 2008 17:04
by ericdes
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();
            }

Posted: Fri 26 Dec 2008 09:39
by Shalex
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();
...