ravl
asked on
.NET - "Specified cast is not valid" error when instantiating oleDBCommand
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.InvalidCastExceptio n: Specified cast is not valid.
Source Error:
Line 12: Public Sub AddCart(ByVal CustomerID As Integer, ByVal ProductID As Integer, ByVal Qty As Double)
Line 13: 'Add a single row item to the cart
Line 14: Dim objCmd As New OleDbCommand("uspAddCart", objConn)
Line 15: objCmd.CommandType = CommandType.StoredProcedur e
Line 16:
The error refers to line 14. At one stage this was working. Now all of a sudden it's not! And all functions containing code like line 14 now fail the same way. Any ideas please?
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.InvalidCastExceptio
Source Error:
Line 12: Public Sub AddCart(ByVal CustomerID As Integer, ByVal ProductID As Integer, ByVal Qty As Double)
Line 13: 'Add a single row item to the cart
Line 14: Dim objCmd As New OleDbCommand("uspAddCart",
Line 15: objCmd.CommandType = CommandType.StoredProcedur
Line 16:
The error refers to line 14. At one stage this was working. Now all of a sudden it's not! And all functions containing code like line 14 now fail the same way. Any ideas please?
stupid question: the variable objConn is of type OleDbConnection, right?
I bet that is it.
ASKER
The problem is certainly with obConn. I am using:
Private objConn = CType(configurationAppSett ings.GetVa lue("DSN", GetType(System.String)), String)
Dim strConnectionString = "Provider=Microsoft.Jet.Ol eDB.4.0;Da ta Source=C:\Files\vsDotNet\P rovidenceV ineyard\da tabase\Pro videnceDat a.mdb"
and DSN is defined in webconfig <appsettings> as:
<add key="DSN" value="Provider=Microsoft. Jet.OleDB. 4.0;Data Source=C:\Files\vsDotNet\T est\databa se\Provide nceData.md b" />
WHat am I missing?
Private objConn = CType(configurationAppSett
Dim strConnectionString = "Provider=Microsoft.Jet.Ol
and DSN is defined in webconfig <appsettings> as:
<add key="DSN" value="Provider=Microsoft.
WHat am I missing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.