[Mono-list] Npgsql error
Francisco Figueiredo Jr.
fxjrlists at yahoo.com.br
Fri Aug 5 09:12:43 EDT 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Fabian Salamanca Dominguez wrote:
>
> Hi
>
Hi Fabian!
> I tried to compile a simple C# program and access a Postgresql DB but I
> got this error in runtime (it compiled with no errors) :
>
> [fsalaman at ipdserver Mono]$ mcs dbaccess.cs -r:Npgsql.dll -r:System.Data.dll
> [fsalaman at ipdserver Mono]$ mono dbaccess.exe
>
> Unhandled Exception: System.InvalidCastException: Cannot cast from
> source type to destination type.
> in <0x000e1> dbAccess:Main (System.String[] args)
> string sql =
> "SELECT operatingsystem, nodeid " +
> "FROM assets";
What are the sql types of operatingsystem and nodeid?
Npgsql doesn't do any implicit conversion of types.
> dbcmd.CommandText = sql;
> IDataReader reader = dbcmd.ExecuteReader();
> while(reader.Read()) {
> string operatingsystem = (string) reader["operatingsystem"];
> string nodeid = (string) reader["nodeid"];
> Console.WriteLine("OS: " +
> operatingsystem + " " + nodeid);
> }
To be sure, do the following:
Console.WriteLine(reader["operatingsystem"].GetType());
This will show you what type is being returned.
I hope it helps.
- --
Regards,
Francisco Figueiredo Jr.
Npgsql Lead Developer
http://gborg.postgresql.org/project/npgsql
MonoBrasil Project Founder Member
http://monobrasil.softwarelivre.org
- -------------
"Science without religion is lame;
religion without science is blind."
~ Albert Einstein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iQEVAwUBQvNlyv7iFmsNzeXfAQLKzAf/V/qotjEIx6JH9HS7zGcrlLzfUad71xeP
WVgR8xo7TkYVvM0rThA3QLk9nlzT+1MLwlLwLO+HjTvz60vgEUmcWwbTFqjbZnt0
hkTmokXeVAdQjLjUsPRAb5xPPcuT89YnGtrfSdpv7wLe/BXJMT/JXE9C/94BuXiB
NL+50QpUQc9ZAKGwcZ4qkO1cDCIi+cLTgjdPBAqOxInLFzYvAbkAgd/yKn1EkRYC
/UYdtsQDdE6ie0dyPh9Q1L6tlBE0bNa7ol0sbY7OjuFtEkx2DvjOycrdMjjCt7HJ
1YkWLIlxUy6lMSzSnYwl7c0RRAgRVeBKldqknPYp9NbfCyC994NGzA==
=txOv
-----END PGP SIGNATURE-----
_______________________________________________________
Yahoo! Acesso Grátis - Internet rápida e grátis.
Instale o discador agora! http://br.acesso.yahoo.com/
More information about the Mono-list
mailing list