954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ADO.NET Specified cast is not valid

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:


Line 12: Public Sub AddCart(ByVal CustomerID As Integer, ByVal ProductID As Integer, ByVal Qty As Integer)
Line 13: 'Add a single row item to the cart
Line 14: Dim objCmd As New OleDbCommand("uspAddCart", objConn)
Line 15: objCmd.CommandType = CommandType.StoredProcedure
Line 16:

Problem is line 14, but why? Everything was working - now it isn't! What might I have done?

Connection info:
Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader

Private objConn = CType(configurationAppSettings.GetValue("DSN", GetType(System.String)), String)

...and in Web.config:

ralaing
Newbie Poster
6 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 
Private objConn = CType(configurationAppSettings.GetValue("DSN", GetType(System.String)), String)


objConn as no variable type...?

Tekmaven
Software Architect
Moderator
1,274 posts since Feb 2002
Reputation Points: 322
Solved Threads: 28
 
objConn as no variable type...?

Sorry, still trying to get a handle on this stuff. If the following works for an SQL connection, why doesn't similar code work for oleDB?

Private objConn As SqlConnection
Private objCmd As SqlCommand
Private dsn As String = ConfigurationSettings.AppSettings("dsn")

Public Function GetSingleTaskObs(ByVal intObservationID As Integer) As SqlDataReader
'Get Base observation details for a given ObservationID
Try
objConn = New SqlConnection(dsn)
objCmd = New SqlCommand("usp_GetObservation", objConn)
objCmd.CommandType = CommandType.StoredProcedure

ralaing
Newbie Poster
6 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You