Posted on Sunday, October 10, 2010 6:54:57 PM and it has been read 12468 times since then.
DataBinding GridView In Asp.NET Application By Using PostgreSQL as DataSource
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Npgsql;
using NpgsqlTypes;
using System.Data;
namespace SamplePostgreSQL1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable table = GetData();
GridView1.DataSource = GetData();
GridView1.DataBind();
}
public DataTable GetData()
{
string conString = "Server=127.0.0.1;Port=5433; Userid=postgres;Password=mypassword; Protocol=3;SSL=false;Pooling=true;MinPoolSize=1; MaxPoolSize=20;Encoding=UNICODE; Timeout=15;SslMode=Disable;Database=Northwind";
DataTable ourDataTable = null;
using (Npgsql.NpgsqlConnection connection = new Npgsql.NpgsqlConnection(conString))
{
try
{
ourDataTable = new DataTable();
Npgsql.NpgsqlDataAdapter ourAdapter = new NpgsqlDataAdapter(@"customerList1", connection);
ourAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
ourAdapter.Fill(ourDataTable);
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
return ourDataTable;
}
}
}
CREATE OR REPLACE FUNCTION customerlist1() RETURNS SETOF "Customers" AS
$BODY$
SELECT * FROM "Customers";
$BODY$
LANGUAGE sql VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION customerlist1() OWNER TO postgres;