System.InvalidCastException: Object must implement IConvertible ???

Posted on 2005-05-05
Last Modified: 2007-12-19
I have created a web page that saves the information that is input into a small access database.
When I click my save button I get the error page showing.

Its prob something simple but I'm a newbie to programming so help would be appreciated!!

System.InvalidCastException: Object must implement IConvertible.

[InvalidCastException: Object must implement IConvertible.]
   System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +122
   System.Data.OleDb.OleDbParameter.GetParameterValue() +173
   System.Data.OleDb.OleDbParameter.GetParameterScale() +28
   System.Data.OleDb.OleDbParameter.BindParameter(Int32 i, DBBindings bindings, tagDBPARAMBINDINFO[] bindInfo) +129
   System.Data.OleDb.OleDbCommand.CreateAccessor() +152
   System.Data.OleDb.OleDbCommand.InitializeCommand(CommandBehavior behavior, Boolean throwifnotsupported) +175
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +22
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +67
   ASP.new_quote_aspx.AddQuote(String title, String firstname, String surname, String housename, String houseNumber, String street, String locality, String town, String county, String postcode, String hometel, String worktel, String mobtel, String email, Boolean pWindows, Boolean pDoors, Boolean pRoofline, Boolean pGaragedoors) +2423
   ASP.new_quote_aspx.btnSave_Click(Object sender, EventArgs e) +306
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1292
Question by:KevNet
    LVL 20

    Expert Comment

    The error is usually becaused of passing an unacceptable object value to OleDbParameter. Please post your code which creating the OleDbParameter parameters, it should be able to show what's wrong in there.
    LVL 5

    Author Comment

    Function AddQuote( _
                    ByVal title As String,  _
                    ByVal firstname As String,  _
                    ByVal surname As String,  _
                    ByVal housename As String,  _
                    ByVal houseNumber As string,  _
                    ByVal street As String,  _
                    ByVal locality As String,  _
                    ByVal town As String,  _
                    ByVal county As String,  _
                    ByVal postcode As String,  _
                    ByVal hometel As String,  _
                    ByVal worktel As String,  _
                    ByVal mobtel As String,  _
                    ByVal email As String,  _
                    ByVal pWindows As Boolean,  _
                    ByVal pDoors As Boolean,  _
                    ByVal pRoofline As Boolean,  _
                    ByVal pGaragedoors As Boolean) As Integer
            Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" & Server.MapPath("database/quotes.mdb")
            Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

            Dim queryString As String = "INSERT INTO [quotes] ([Title], [Firstname], [Surname], [Housename], [HouseNumber]"& _
    ", [Street], [Locality], [Town], [County], [Postcode], [Hometel], [Worktel], [Mob"& _
    "tel], [Email], [PWindows], [PDoors], [PRoofline], [PGaragedoors]) VALUES (@Title"& _
    ", @Firstname, @Surname, @Housename, @HouseNumber, @Street, @Locality, @Town, @Co"& _
    "unty, @Postcode, @Hometel, @Worktel, @Mobtel, @Email, @PWindows, @PDoors, @PRoof"& _
    "line, @PGaragedoors)"
            Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection

            Dim dbParam_title As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_title.ParameterName = "@Title"
            dbParam_title.Value = txtTitle.text
            dbParam_title.DbType = System.Data.DbType.String
            Dim dbParam_firstname As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_firstname.ParameterName = "@Firstname"
            dbParam_firstname.Value = txtfirstname.text
            dbParam_firstname.DbType = System.Data.DbType.String
            Dim dbParam_surname As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_surname.ParameterName = "@Surname"
            dbParam_surname.Value = txtsurname.text
            dbParam_surname.DbType = System.Data.DbType.String
            Dim dbParam_housename As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_housename.ParameterName = "@Housename"
            dbParam_housename.Value = txthousename.text
            dbParam_housename.DbType = System.Data.DbType.String
            Dim dbParam_houseNumber As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_houseNumber.ParameterName = "@HouseNumber"
            dbParam_houseNumber.Value = txthouseNo.text
            dbParam_houseNumber.DbType = System.Data.DbType.String
            Dim dbParam_street As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_street.ParameterName = "@Street"
            dbParam_street.Value = txtstreet.text
            dbParam_street.DbType = System.Data.DbType.String
            Dim dbParam_locality As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_locality.ParameterName = "@Locality"
            dbParam_locality.Value = txtlocality.text
            dbParam_locality.DbType = System.Data.DbType.String
            Dim dbParam_town As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_town.ParameterName = "@Town"
            dbParam_town.Value = txttown.text
            dbParam_town.DbType = System.Data.DbType.String
            Dim dbParam_county As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_county.ParameterName = "@County"
            dbParam_county.Value = txtcounty.text
            dbParam_county.DbType = System.Data.DbType.String
            Dim dbParam_postcode As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_postcode.ParameterName = "@Postcode"
            dbParam_postcode.Value = txtpostcode.text
            dbParam_postcode.DbType = System.Data.DbType.String
            Dim dbParam_hometel As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_hometel.ParameterName = "@Hometel"
            dbParam_hometel.Value = txthometel.text
            dbParam_hometel.DbType = System.Data.DbType.String
            Dim dbParam_worktel As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_worktel.ParameterName = "@Worktel"
            dbParam_worktel.Value = txtworktel.text
            dbParam_worktel.DbType = System.Data.DbType.String
            Dim dbParam_mobtel As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_mobtel.ParameterName = "@Mobtel"
            dbParam_mobtel.Value = txtmobtel.text
            dbParam_mobtel.DbType = System.Data.DbType.String
            Dim dbParam_email As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_email.ParameterName = "@Email"
            dbParam_email.Value = txtemail.text
            dbParam_email.DbType = System.Data.DbType.String
            Dim dbParam_pWindows As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_pWindows.ParameterName = "@PWindows"
            dbParam_pWindows.Value = chkWindows
            dbParam_pWindows.DbType = System.Data.DbType.Boolean
            Dim dbParam_pDoors As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_pDoors.ParameterName = "@PDoors"
            dbParam_pDoors.Value = chkDoors
            dbParam_pDoors.DbType = System.Data.DbType.Boolean
            Dim dbParam_pRoofline As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_pRoofline.ParameterName = "@PRoofline"
            dbParam_pRoofline.Value = chkRoofline
            dbParam_pRoofline.DbType = System.Data.DbType.Boolean
            Dim dbParam_pGaragedoors As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_pGaragedoors.ParameterName = "@PGaragedoors"
            dbParam_pGaragedoors.Value = chkGaragedoors
            dbParam_pGaragedoors.DbType = System.Data.DbType.Boolean

            Dim rowsAffected As Integer = 0
                rowsAffected = dbCommand.ExecuteNonQuery
            End Try

            Return rowsAffected
        End Function
    LVL 20

    Accepted Solution

    dbParam_pWindows.Value = chkWindows
    dbParam_pDoors.Value = chkDoors
    let me guess, checkboxes? that should be

    dbParam_pWindows.Value = chkWindows.Checked
    dbParam_pDoors.Value = chkDoors.Checked

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video discusses moving either the default database or any database to a new volume.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now