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.
PgSqlDataTable not available for ASP.NET?
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();
}
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();
}
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();
...