943,662 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 74707
  • ASP.NET RSS
Aug 6th, 2004
0

ADO.NET Specified cast is not valid

Expand Post »
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:
<add key="DSN" value="Provider=Microsoft.Jet.OleDB.4.0;Data Source=c:\files\access\data\ProvidenceData.mdb" />
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ralaing is offline Offline
6 posts
since Aug 2004
Aug 6th, 2004
0

Re: ADO.NET Specified cast is not valid

Quote originally posted by ralaing ...
Private objConn = CType(configurationAppSettings.GetValue("DSN", GetType(System.String)), String)
objConn as no variable type...?
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Aug 10th, 2004
0

Re: ADO.NET Specified cast is not valid

Quote originally posted by Tekmaven™ ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ralaing is offline Offline
6 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Use of DataGrid
Next Thread in ASP.NET Forum Timeline: My first attempt at ASP.NET...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC