<%@ 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</title>
<script language="C#" runat="Server">
private void Page_Load(object sender, System.EventArgs e) {
NpgsqlConnectionconn = null;
NpgsqlCommandcomm = null;
NpgsqlDataAdaptersda = 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\";";
sda = new NpgsqlDataAdapter(comm);
sda.Fill(ds);
dgCustomers.DataSource = ds;
dgCustomers.DataBind();
} 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();
}
sda.Dispose()
comm.Dispose()
conn.Dispose()
} }
</script></head>
<body>
<form id="frmPostgreSQLExample" method="post" runat="server">
<asp:DataGrid id="dgCustomers" runat="server" />
</form></body></html>