Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 15th, 2006, 03:08 PM
Registered User
 
Join Date: Oct 2006
Location: Coppell, TX, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object must implement IConvertible.

I have a form that is passed a phone number and takes the phone number and populates the form. Users make changes and click a button to update the database. I am getting the following error message. I am struggling to understand what I am doing wrong?

Object must implement IConvertible.
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: Object must implement IConvertible.

Source Error:


Line 316: cmd.Parameters("@CB").Value = txtCB.Text
Line 317:
Line 318: cmd.ExecuteNonQuery()
Line 319: Catch exSql As SqlException
Line 320: 'lblError.Text = "ERROR: Unable to update database"


Source File: c:\inetpub\wwwroot\FMS\frmSalesLeadsAdmin.aspx.vb Line: 318

Stack Trace:


[InvalidCastException: Object must implement IConvertible.]
   System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   FMS.frmSalesLeadsAdmin.Update() in c:\inetpub\wwwroot\FMS\frmSalesLeadsAdmin.aspx.vb: 318
   FMS.frmSalesLeadsAdmin.btnUpdate_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\FMS\frmSalesLeadsAdmin.aspx.vb: 383
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
   System.Web.UI.Page.ProcessRequestMain()


HERE MY CODE FOR UPDATING
Private Sub Update()
        Dim cnn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
        Try
            cnn.Open()
            Dim cmd As SqlCommand = cnn.CreateCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "procUpdateSalesLead"

            'pass the phone to database for searching
            cmd.Parameters.Add(New SqlParameter("@Company", SqlDbType.VarChar, 255))
            cmd.Parameters("@Company").Value = txtSearch.Text

            cmd.Parameters.Add(New SqlParameter("@StreetAddress", SqlDbType.VarChar, 255))
            cmd.Parameters("@StreetAddress").Value = txtAddress.Text

            cmd.Parameters.Add(New SqlParameter("@City", SqlDbType.VarChar, 255))
            cmd.Parameters("@City").Value = txtCity

            cmd.Parameters.Add(New SqlParameter("@State", SqlDbType.VarChar, 50))
            cmd.Parameters("@State").Value = cboState.SelectedValue

            cmd.Parameters.Add(New SqlParameter("@Zip", SqlDbType.Int, 4))
            cmd.Parameters("@Zip").Value = CInt(txtZip.Text)

            cmd.Parameters.Add(New SqlParameter("@Phone", SqlDbType.VarChar, 10))
            cmd.Parameters("@Phone").Value = txtPhone.Text

            cmd.Parameters.Add(New SqlParameter("@ContactTypeID", SqlDbType.Int, 4))
            cmd.Parameters("@ContactTypeID").Value = cboContactType

            cmd.Parameters.Add(New SqlParameter("@FaxNumber", SqlDbType.VarChar, 10))
            cmd.Parameters("@FaxNumber").Value = txtFax.Text

            cmd.Parameters.Add(New SqlParameter("@WebAddress", SqlDbType.VarChar, 100))
            cmd.Parameters("@WebAddress").Value = txtURL.Text

            cmd.Parameters.Add(New SqlParameter("@ContactName", SqlDbType.VarChar, 255))
            cmd.Parameters("@ContactName").Value = txtContact.Text

            cmd.Parameters.Add(New SqlParameter("@Title", SqlDbType.VarChar, 50))
            cmd.Parameters("@Title").Value = txtTitle.Text

            cmd.Parameters.Add(New SqlParameter("@Gender", SqlDbType.VarChar, 50))
            cmd.Parameters("@Gender").Value = cboSex.SelectedValue

            cmd.Parameters.Add(New SqlParameter("@NumberOfEmployees", SqlDbType.Int, 4))
            cmd.Parameters("@NumberOfEmployees").Value = CInt(txtNumOfEmpl.Text)

            cmd.Parameters.Add(New SqlParameter("@Revenue", SqlDbType.VarChar, 50))
            cmd.Parameters("@Revenue").Value = txtRev.Text

            cmd.Parameters.Add(New SqlParameter("@Industry", SqlDbType.VarChar, 255))
            cmd.Parameters("@Industry").Value = txtIndustry.Text

            cmd.Parameters.Add(New SqlParameter("@Ext", SqlDbType.Int, 4))
            cmd.Parameters("@Ext").Value = CInt(txtExt.Text)

            cmd.Parameters.Add(New SqlParameter("@AlternativeNumber", SqlDbType.VarChar, 50))
            cmd.Parameters("@AlternativeNumber").Value = txtAlt.Text

            cmd.Parameters.Add(New SqlParameter("@MobilePhone", SqlDbType.VarChar, 10))
            cmd.Parameters("@MobilePhone").Value = txtCell.Text

            cmd.Parameters.Add(New SqlParameter("@EmailAddress", SqlDbType.NVarChar, 100))
            cmd.Parameters("@EmailAddress").Value = txtEmail.Text

            cmd.Parameters.Add(New SqlParameter("@Notes", SqlDbType.VarChar, 255))
            cmd.Parameters("@Notes").Value = txtNotes.Text

            cmd.Parameters.Add(New SqlParameter("@NI", SqlDbType.VarChar, 10))
            cmd.Parameters("@NI").Value = txtNI.Text

            cmd.Parameters.Add(New SqlParameter("@LM", SqlDbType.VarChar, 10))
            cmd.Parameters("@LM").Value = txtLM.Text

            cmd.Parameters.Add(New SqlParameter("@CB", SqlDbType.VarChar, 10))
            cmd.Parameters("@CB").Value = txtCB.Text

            cmd.ExecuteNonQuery()
        Catch exSql As SqlException
            'lblError.Text = "ERROR: Unable to update database"
            lblError.Text = exSql.Message() + "" + exSql.Source() + "" + exSql.StackTrace()
        Finally
            cnn.Close()
            cnn.Dispose()
            cnn = Nothing
        End Try
    End Sub


HERE IS MY STORED PROCEDURE CODE
CREATE PROCEDURE procUpdateSalesLead
(
    @Company varchar(255),
    @StreetAddress varchar(255),
    @City varchar(255),
    @State varchar(55),
    @Zip int,
    @Phone nvarchar(10),
    @ContactTypeID int,
    @FaxNumber nvarchar(10),
    @WebAddress varchar(255),
    @ContactName varchar(255),
    @Title varchar(100),
    @Gender varchar(50),
    @NumberOfEmployees int,
    @Revenue varchar(50),
    @Industry varchar(255),
    @Ext int,
    @AlternativeNumber varchar(10),
    @MobilePhone varchar(10),
    @EmailAddress varchar(255),
    @Notes nvarchar(255),
    @NI varchar(10),
    @LM varchar(10),
    @CB varchar(10)
)
AS
UPDATE tblSalesLeads
SET

             Company = @Company,
    StreetAddress = @StreetAddress,
    City = @City,
    State = @State,
    Zip = @Zip,
    Phone = @Phone,
    ContactTypeID = @ContactTypeID,
    FaxNumber = @FaxNumber,
    WebAddress = @WebAddress,
    ContactName = @ContactName,
    Title = @Title,
    Gender = @Gender,
    NumberOfEmployees = @NumberOfEmployees,
    Revenue = @Revenue,
    Industry = @Industry,
    Ext = @Ext,
    AlternativeNumber = @AlternativeNumber,
    MobilePhone = @MobilePhone,
    EmailAddress = @EmailAddress,
    Notes = @Notes ,
    NI = @NI,
    LM = @LM,
    CB = @CB

WHERE Phone = @Phone
GO


  #2 (permalink)  
Old December 15th, 2006, 03:15 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. i dont have a clue about your error.. but i can say that using the phone number as the table key is wrong, because the user cannot change it if they make a mistake...

see that if you are trying to update your phone number your SP will fail...



HTH

Gonzalo
  #3 (permalink)  
Old December 15th, 2006, 03:29 PM
Registered User
 
Join Date: Oct 2006
Location: Coppell, TX, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just changed the stored procedure. I didn't want the user to be able to edit the phone number. I just wanted the user to be able to update the record related to a particular phone number. The phone number is used to verify if a client currently exits in the database and prevent duplicate sales leads from getting into the database.

I still get the same error :-(

  #4 (permalink)  
Old December 15th, 2006, 03:42 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

i think i found your problem..

cmd.Parameters("@City").Value = txtCity has .text missing..

cmd.Parameters("@ContactTypeID").Value = cboContactType has something missing (text?, selectedvalue?)

fix that and tell me...



HTH

Gonzalo
  #5 (permalink)  
Old December 15th, 2006, 05:15 PM
Registered User
 
Join Date: Oct 2006
Location: Coppell, TX, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I fixed it. I changed the data type for NI, CB, LM from smalldatetime to varchar and it works fine now.

  #6 (permalink)  
Old December 15th, 2006, 05:37 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmmmm. The error you got doesn't seem to lend itself to a datatype conversion error. For example, in your stored procedure if you decare and input parameter as smalldatetime and you try to pass in a date of 12/31/2100 your code will throw a SqlEception similiar to this:

Error converting Varchar value to type smalldatetime.

The IConvertiable interface is the interface that allows us to do Convert.ToString() and such and most objects that we work with in .NET implement this interface.

I am in agreeance with Gonzalo here; you definately have some syntax errors and, if just changing your procedure datatypes resovled this problem ,i would check the data you are passing in because it may be invalid. (E.g. your data field may contain System.Windows.Forms.Textbox)

Something doesnt make sense.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
  #7 (permalink)  
Old December 15th, 2006, 07:40 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mmm.. they were varchar in the code you gave us...
are you sure that was all the problem???

HTH

Gonzalo
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object must implement IConvertible. shwetarani2002 ASP.NET 1.0 and 1.1 Basics 0 June 25th, 2007 07:16 AM
Object must implement IConvertable furqanms C# 0 December 1st, 2006 03:08 AM
IConvertible Error hoailing22 ASP.NET 1.0 and 1.1 Basics 5 March 16th, 2006 12:18 AM
IConvertible error problem geek.net ADO.NET 1 February 14th, 2006 06:44 PM
Stored procedure IConvertible nk15 SQL Server ASP 1 November 1st, 2004 03:22 PM



All times are GMT -4. The time now is 09:13 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.