[Mono-list] Npgsql myCommand.ExecuteScalar type cast issue

Joe Audette joe_audette at yahoo.com
Fri Dec 23 15:35:15 EST 2005

I think 
i = Convert.ToInt32(myCommand.ExecuteScalar());

will work

Hope it helps,

joe_audette [at] yahoo dotcom 

----- Original Message ----
From: Christopher Bergström <cbergstrom at netsyncro.com>
To: Mono List <mono-list at lists.ximian.com>
Sent: Friday, December 23, 2005 2:30:19 PM
Subject: [Mono-list] Npgsql myCommand.ExecuteScalar type cast issue

int i = 0;

// This works and does prints "1".

// This results in the error below.
i = (int)myCommand.ExecuteScalar();

System.InvalidCastException: Cannot cast from source type to destination type.
in <0x000c3> ASP.login_aspx:CheckUserCredentials (System.String username, System.String password)
in <0x00065> ASP.login_aspx:btnSubmit_Click (System.Object sender, System.EventArgs e)
in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_object_EventArgs (object,System.EventArgs)
in <0x00066> System.Web.UI.WebControls.Button:OnClick (System.EventArgs e)
in <0x00045> System.Web.UI.WebControls.Button:RaisePostBackEvent (System.String eventArgument)
in <0x0000d> System.Web.UI.WebControls.Button:System.Web.UI.IPostBackEventHandler.RaisePostBackEvent (System.String eventArgument)
in <0x00016> System.Web.UI.Page:RaisePostBackEvent (IPostBackEventHandler sourceControl, System.String eventArgument)
in <0x00031> System.Web.UI.Page:RaisePostBackEvents ()
in <0x001ee> System.Web.UI.Page:InternalProcessRequest ()
in <0x000a4> System.Web.UI.Page:ProcessRequest (System.Web.HttpContext context)

The value should* be able to cast into an int?  I'm converting some stuff off SQL server and the equivalent code works in mono.. The only thing I can think is I'm testing this on my dev server which is using a different version of Mono/Npgsql.  Anyone have any ideas.. I'll play with boxing/unboxing, assuming ExecuteScalar returns an object, to see if it's a Mono or Npqsql issue and if it's in SVN head.



Mono-list maillist  -  Mono-list at lists.ximian.com

More information about the Mono-list mailing list