[Mono-list] Npgsql error

Daniel Morgan monodanmorg at yahoo.com
Fri Aug 5 14:45:10 EDT 2005


If you wanted them both to be string, you could have:
 
string operatingsystem = reader["operatingsystem"].ToString();
string nodeid = reader["nodeid"].ToString();
 
Or if needed the int, you could have:
 
string operatingsystem = reader.GetString(reader.GetOrdinal("operatingsystem"));
int nodeid = reader.GetInt32(reader.GetOrdinal("nodeid"));
 
Fabian Salamanca Dominguez <fsalaman at gmail.com> wrote:

Thanks to all!!

The last one prints:

System.String System.Int32

never prints null, I'll try the other suggestions...

java-ish lol, what's java?

On 8/5/05, Francisco Figueiredo Jr. <fxjrlists at yahoo.com.br> wrote: -----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/
_______________________________________________
Mono-list maillist  -   Mono-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list




-- 
Fabian _______________________________________________
Mono-list maillist - Mono-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list

		
---------------------------------
 Start your day with Yahoo! - make it your home page 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20050805/ea71500f/attachment-0001.html


More information about the Mono-list mailing list