Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > System.InvalidCastException: Specified cast is not valid.

Thread Tools

System.InvalidCastException: Specified cast is not valid.

Posts: n/a

Anybody help me regarding this error:

I am assigning the values to the session variables when the button is
clicked and passing these session variables to the next page and when I am
printing these session variables they are printing. After that I am
assigning these things in hidden object and in the form submit action I am
receiving these hidden values like the following:

dim Recname = Request("Recname")
dim Contactname = Request("Contactname")
dim CompAddress = Request("Compaddress")
dim city = Request("City")
dim ZipCode = Request("Zipcode")
dim Country = Request("Country")
dim TelePhone = Request("Telephone")
dim Mobile = Request("Mobile")
dim Email = Request("Emailid")
dim Companysite = Request("Companysite")
dim Sector = Request("Sector")
dim Functional = Request("Functional")
dim Yroperation = Request("Yroperation")
dim Officeloc = Request("Officeloc")
dim Usesite = Request("Usesite")
dim Billaddress = Request("Billaddress")
dim Billcity = Request("Billcity")
dim Billzip = Request("Billzip")
dim Billctr = Request("Billcountry")
dim Resumeflag = Request("Resumeflag")
dim Resumeemail = Request("Resumeemail")
dim Resumereg = "NO"
dim Recapprove = "YES"

Here also I succeeded when I am printing these declared variables with
assigned values. But when I am trying to insert these vales into the table
created in MS-Access like the following it is producing the given error:

(Recname,Contname,Recaddress,Reccity,ReczipCode,Re ccountry,RecTelephone,Recmobile,Recemail,Recsite,R ecsector,Recfunctional,Recyroper,Recusesite,Recbil laddress,Recbillcity,Recbillzip,Recbillcountry,Rec resumeflag,Recresumemail,Regdate,Recofficelocation s,Recapprove,Recapproveres)
(@Rname,@Contname,@Raddress,@Rcity,@Rzip,@Rcountry ,@Rphone,@Rmobile,@Remail,@Rsite,@Rsector,@Rfuncti on,@Ryear,@Rusite,@Rbilladd,@Rbillcty,@Rbillzip,@R billctr,@Rflag,@RRemail,@RRegdate,@Roffice,@Rappro ve,@RRapprove)"

oComm = New OleDbCommand(sSQL, oConn)
oComm.Commandtype = CommandType.Text

oComm.Parameters.Add(New OleDbParameter("@Rname", UCASE(Recname)))
oComm.Parameters.Add(New OleDbParameter("@Contname", UCASE(Contactname)))
oComm.Parameters.Add(New OleDbParameter("@Raddress", UCASE(Compaddress)))
oComm.Parameters.Add(New OleDbParameter("@RCity", UCASE(City)))
oComm.Parameters.Add(New OleDbParameter("@Rzip", Zipcode))
oComm.Parameters.Add(New OleDbParameter("@Rcountry", UCASE(Country)))
oComm.Parameters.Add(New OleDbParameter("@Rphone", UCASE(Telephone)))
oComm.Parameters.Add(New OleDbParameter("@Rmobile", UCASE(Mobile)))
oComm.Parameters.Add(New OleDbParameter("@Remail", UCASE(Email)))
oComm.Parameters.Add(New OleDbParameter("@Rsite", UCASE(Companysite)))
oComm.Parameters.Add(New OleDbParameter("@Rsector", UCASE(Sector)))
oComm.Parameters.Add(New OleDbParameter("@Rfunction", UCASE(Functional)))
oComm.Parameters.Add(New OleDbParameter("@Ryear", Yroperation))
oComm.Parameters.Add(New OleDbParameter("@Rusite", UCASE(Usesite)))
oComm.Parameters.Add(New OleDbParameter("@Rbilladd", UCASE(Billaddress)))
oComm.Parameters.Add(New OleDbParameter("@Rbillcty", UCASE(Billcity)))
oComm.Parameters.Add(New OleDbParameter("@Rbillzip", UCASE(Billzip)))
oComm.Parameters.Add(New OleDbParameter("@Rbillctr", UCASE(Billctr)))
oComm.Parameters.Add(New OleDbParameter("@Rflag", UCASE(Resumeflag)))
oComm.Parameters.Add(New OleDbParameter("@RRemail", Resumeemail))
oComm.Parameters.Add(New OleDbParameter("@RRegdate", now()))
oComm.Parameters.Add(New OleDbParameter("@Roffice", UCASE(Officeloc)))
oComm.Parameters.Add(New OleDbParameter("@Rapprove", UCASE(Recapprove)))
oComm.Parameters.Add(New OleDbParameter("@RRapprove", UCASE(Resumereg)))


Line 65:
Line 66:
Line 67: oComm.ExecuteNonQuery()
Line 68:
Line 69:
Source File: recruiter\Recok.aspx Line: 67

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
System.Data.OleDb.DBBindings.set_Value(Object value) +1886
System.Data.OleDb.OleDbCommand.GetInputParameters( ) +100
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,
Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +66

[TargetInvocationException: Exception has been thrown by the target of an
System.Reflection.RuntimeMethodInfo.InternalInvoke (Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess) +0
System.Reflection.RuntimeMethodInfo.InternalInvoke (Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean verifyAccess) +425
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +23
Microsoft.VisualBasic.CompilerServices.LateBinding .FastCall(Object o,
MethodBase method, ParameterInfo[] Parameters, Object[] args, Type objType,
IReflect objIReflect) +247
Microsoft.VisualBasic.CompilerServices.LateBinding .InternalLateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack, Boolean IgnoreReturn) +435

Microsoft.VisualBasic.CompilerServices.LateBinding .LateCall(Object o,
Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack) +23
ASP.Recok_aspx.__Render__control1(HtmlTextWriter __output, Control
parameterContainer) in
c:\websites\managersp65\\newinaspx\re cruiter\Recok.aspx:67
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +27
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Page.ProcessRequestMain() +1926

I am not using any codebehinds but passing the session variables from a
procedure which is called at the time of button press event is fired.
Please help me to solve this problem.

Reply With Quote
Posts: n/a
Ensure that the values that you are providing are of correct data-type.

Request("...") returns only and only string.
If you are using int / nvarchar etc, typecast it accordingly first. I
think the issue, most likely, would be with numeric fields.

Check it.

Gaurav Vaish

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: specified cast is not valid. Why not? Alan Silver ASP .Net 5 02-15-2005 08:08 PM
User Control - InvalidCastException: Specified cast is not valid Ajit ASP .Net 1 04-24-2004 09:28 PM
I get the following error ( Specified cast is not valid ) with Server.Transfer Andrew ASP .Net 0 08-12-2003 08:26 PM
System.InvalidCastException: Specified cast is not valid. Arjen ASP .Net 1 08-06-2003 03:26 AM
System.InvalidCastException: Specified cast is not valid Floela ASP .Net 3 07-10-2003 10:36 AM