<%@ Page language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Npgsql" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html><head><title>PostgreSQL Example 2</title>
<script language="C#" runat="Server">
private void Page_Load(object sender, System.EventArgs e) {
NpgsqlConnectionconn = null;
NpgsqlCommandcomm = null;
NpgsqlDataReadersdr = null;
DataSetds = new DataSet();
try {
conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Userid=Test;password=test;Protocol=3;SSL=false;Pooling=true;MinPoolSize=1;MaxPoolSize=20;Encoding=UNICODE;Timeout=15;SslMode=Disable");
comm = new NpgsqlCommand();
comm.Connection = conn;
conn.Open();
comm.CommandType = CommandType.Text;
comm.CommandText = "SELECT * FROM \"Customers\";";
sdr = comm.ExecuteReader();
Response.Write("<table border=\"1\">");
Response.Write("<tr><th>Last Name</th><th>First Name</th></tr>");
while (sdr.Read()) {
Response.Write("<tr>");
Response.Write("<td>");
Response.Write(sdr[0]);
Response.Write("</td>");
Response.Write("<td>");
Response.Write(sdr[1]);
Response.Write("</td>");
Response.Write("</tr>");
}
Response.Write("</table>");
sdr.Close();
} catch (Npgsql.NpgsqlException ex){
Response.Write("Postgre Exception: " + ex.ToString());
} catch (Exception ex) {
Response.Write("Exception: " + ex.ToString());
} finally {
if (conn.State == System.Data.ConnectionState.Open) {
conn.Close();
}
conn.Dispose();
comm.Dispose();
sdr.Dispose();
} }
</script> </head><body>
<form id="frmPostgreSQLExample2" method="post" runat="server">
<asp:DataGrid id="dgCustomers" runat="server" />
</form></body></html>