I've to modify the Npgsql example from http://go-mono.com/postgresql.html , check this code:
================ postgresTest.cs ==============
using System;
using System.Data;
using Npgsql;
public class Test
{
public static void Main(string[] args)
{
string connectionString =
"Server=127.0.0.1;" +
"Database=DBF;" +
"User ID=angel;" +
"Password=********;";
//IDbConnection dbcon;
NpgsqlConnection dbcon = new NpgsqlConnection(connectionString);
dbcon.Open();
//dbcon = new NpgsqlConnection(connectionString);
IDbCommand dbcmd = dbcon.CreateCommand();
// requires a table to be created named employee
// with columns firstname and lastname
// such as,
// CREATE TABLE employee (
// firstname varchar(32),
// lastname varchar(32));
string sql =
"SELECT codemp, cnombre " +
"FROM empresa";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
String FirstName = (String)reader["codemp"];
String LastName = (String)reader["cnombre"];
Console.WriteLine("Name: " +
FirstName + " " + LastName);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
=========================================
Compiling...
mcs -r Npgsql.dll -r System.Data.dll postgresTest.cs
Check Npgsql.dll is located in the same directory as System.Data.dll, usually /usr/lib.
On Tue, 2003-11-18 at 19:18, Roberto Jimeno wrote:
Hi there! Tim, Rodrigo, Daniel, Rafael or someone willing to help a mono/sql newbie here. I'm using Mono 0.28 installed from an RPM file (and I have reasons to stick to the RPM file rather than using CVS) I'm writing some C# code which requires to select some information from a bunch of already-filled tables on a postgres database. I tried to use Mono.Data.PostgreSQL unsuccessfully as well as Npgsql (more details on this at the bottom of the message). Now I don't know what to do: Should I keep on trying with either of those data providers? Should I try to use ByteFX with postgres? Where can I find more information about it? Thanks in advance for helping me. Details on the tests and failures with both data providers: >From http://go-mono.com/postgresql.html I copied verbatim the examples for Mono.Data.PostgreSqlClient and Npgsql named them TestExample.Mono.Data.PostgreSqlClient.cs and TestExample.Npgsql.cs respectively, and then followed the instructions found there, in order to compile and use the examples: When I tried to compile the one using PostgreSqlClient , it failed with "Cannot find type `PgConnection'" Afterwards, I tried to compile the one using Npgsql, which also failed, this time indicating "Use of unassigned local variable `dbcon'" on line 15. >From somewhere (I can't remember where, but the source file is also attached) I copied another test example which compiles on my system, although when I attempt to run the .exe file using mono, it complains about an unhandled exception ("A null value was found where an object instance was required") The command lines Im using to build (or attempt to build) the test examples are as follows: $mcs TestExample.Mono.Data.PostgreSqlClient.cs -r System.Data.dll -r Mono.Data.PostgreSqlClient.dll $mcs TestExample.Npgsql.cs -r System.Data.dll -r Npgsql.dll $mcs OtherTestExample.cs -r System.Data.dll -r Mono.Data.PostgreSqlClient.dll ===== Roberto Jimeno __________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree
-- Angel http://bukox.tripod.com |
