<%@ Page language="vb" %>
<%@ 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="vb" runat="Server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Dim conn As NpgsqlConnection
Dim comm As NpgsqlCommand
Dim sda As NpgsqlDataAdapter
Dim ds As DataSet
ds = 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()
comm.Close()
Catch ex As Npgsql.NpgsqlException
Response.Write("Postgre Exception: " + ex.ToString())
Catch ex As Exception
Response.Write("Exception: " + ex.ToString())
Finally
If (conn.State = System.Data.ConnectionState.Open) Then
conn.Close()
End If
sda.Dispose()
comm.Dispose()
conn.Dispose()
End Try
End Sub
</script></head>
<body>
<form id="frmPostgreSQLExample" method="post" runat="server">
<asp:DataGrid id="dgCustomers" runat="server" />
</form></body></html>