List Info

Thread: ASP.NET example primed for mono-project postgreSQL page




ASP.NET example primed for mono-project postgreSQL page
country flaguser name
United Kingdom
2007-05-16 10:44:13
hi,

I saw the C# example on http://www.mon
o-project.com/PostgreSQL using Npgsql 
and found it very useful in testing installation.

I thought it would benifit others if I refactored it into
ASP.NET/C# as this 
was why I setup postgreSQL.
So I was a bit surprised when found I could not edit the
page or even register 
an account.

Code follows as a single .aspx file run to run on monos
xsp/2, if anyone can 
put it on the webpage I think it would help.

<% Page Language="c#" Title="postgres
via Npgsql" %>
<% Assembly name="System" %>
<% Assembly name="System.Data" %>
<% Assembly name="Npgsql" %>

<script runat="server">
		protected void Page_Load(object sender, EventArgs e) 
		{
			if (!Page.IsPostBack)
			{
		      string connectionString =
          		"Server=localhost;" +
          		"Database=test;" +
          		"User ID=postgres;" +
          		"Password=fun2db;";
		      	System.Data.IDbConnection dbcon;
		       	dbcon = new
Npgsql.NpgsqlConnection(connectionString);
		       	dbcon.Open();
		       	System.Data.IDbCommand dbcmd =
dbcon.CreateCommand();
       			string sql =
           			"SELECT firstname, lastname " +
           			"FROM employee";
		       	dbcmd.CommandText = sql;
		       	System.Data.IDataReader reader =
dbcmd.ExecuteReader();
				dg.DataSource = reader;
				dg.DataBind();
			    reader.Close();
       			reader = null;
       			dbcmd.Dispose();
       			dbcmd = null;
       			dbcon.Close();
       			dbcon = null;
			}
		}
</script>

<html> 
<body>
The DataGrid that follows should list employees </
br>
<aspataGrid
id="dg" runat="server">
</aspataGrid&
gt;
<pre>
       // requires a table to be created named employee
       // with columns firstname and lastname
       // such as,
       //        CREATE TABLE employee (
       //           firstname varchar(32),
       //           lastname varchar(32));
       //
       // create records thus
       //        INSERT INTO employee 
       //           SELECT 'Rob','Davis';
       //        INSERT INTO employee 
       //           SELECT 'Sarah','Davis';
</pre>
</body>
</html>  

Regards

Rob
_______________________________________________
Mono-docs-list maillist  -  Mono-docs-listlists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-docs-list

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )