[thelist] ASP.NET: Specified cast is not valid.

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Mon May 15 20:28:44 CDT 2006

		Not quite.  

   The arrRoles variable is defined as an array of elements of type String; however, ExecuteScalar only yields a single object (which is usually assumed to be a string).

   If you want to populate an array, does that mean you have a delimited string coming back?  If so, you'd need to say something like this (assuming that the pipe character is your delimiter):

arrRoles = cmdSelect.ExecuteScalar().ToString().Split("|") 



				From: "Matt Warden" mwarden at gmail.com

On 5/15/06, Casey Crookston wrote:

> Exception Details: System.InvalidCastException: Specified cast is not
> valid.
> Source Error:
> Line 57: Dim arrRoles As String()
> Line 58: conWiese.Open()
> Line 59: arrRoles = cmdSelect.ExecuteScalar()
> Line 60: conWiese.Close()
> Line 61:
> Source File: C:\Sites\local.wieseford.com\Global.asax.vb Line: 59
> Line 59 is: arrRoles = cmdSelect.ExecuteScalar()

arrRoles = cmdSelect.ExecuteScalar().ToString();

Matt Warden

More information about the thelist mailing list