Francisco Figueiredo Jr. wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joe Audette wrote:
  
Being close to christmas not everyone may be reading the mail but Francisco is the developer of npgsql and I know he follows this list.
 
    

Hi Joe. That was exactly what happened :)


Christopher, do you have a test case for your problem?


To check what type is being returned, add the following:

Console.WriteLine(command.ExecuteScalar().GetType());

What type in your database is the field which you are doing the
executeScalar()?

If you are using an select * from some table, Postgresql changed the
type of the data returned from int4 to int8, which Npgsql translates to
Int64. So, you may be receiving an Int64 and this explains why you may
be not being able to directly cast it to int32.
  
The below returns System.Int64

That's exactly what's going on.. Question is.. How do we handle it..

a) Make the type cast error more explicit?
b) Somehow make it return Int32?

I'm thinking this is pretty common error based on the offlist responses I got.. Could be helpful to document..

<snip>

NpgsqlCommand myCommand = new NpgsqlCommand("SELECT COUNT(*) FROM  tbl_users WHERE  fld_varchar_username='"+txtUsername.Text+"' and fld_varchar_password='"+txtPassword.Text+"';", myConnection);


// This should work for all results where SELECT COUNT (*) < Int64 and the result can be cast into an Int32
int i = (int)myCommand.ExecuteScalar();

</snip>

Where and how do you want me to submit a test case if you still need more info? (I also posted this in the Npgsql forum as well.  Once worked out I'll make sure to follow up and document everything there as well.

Thanks

C.
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to