DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    7

    Question Object Must Implement IConvertible

    This is supposed to fire when a button is clicked, however when the button is clicked I get the following error.

    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 124:
    Line 125: sqlconn.Open();
    Line 126: sqlcmd.ExecuteNonQuery();
    Line 127: sqlconn.Close();
    Line 128:


    This is the code that runs when the button is clicked.



    SqlConnection sqlconn = new SqlConnection("Data Source=vnadbms01;initial catalog=LDMS; " + "integrated security=true;persist security info=True;");
    SqlCommand sqlcmd = new SqlCommand("NWH_Intranet_Update_Employees", sqlconn);


    // SqlCommand cmd = new SqlCommand("NWH_Intranet_Update_Employees", PhoneDirConn);
    sqlcmd.CommandType = CommandType.StoredProcedure;
    sqlcmd.Parameters.Add("@AM_EMPID", SqlDbType.Int).Value = txtEmpID.Text;
    sqlcmd.Parameters.Add("@AM_ADUSER", SqlDbType.VarChar).Value = txtAccnt.Text;
    sqlcmd.Parameters.Add("@AM_BRANCH", SqlDbType.VarChar).Value = txtOffice.Text;
    sqlcmd.Parameters.Add("@AM_DEPARTMENT", SqlDbType.VarChar).Value = txtDepartment.Text;
    sqlcmd.Parameters.Add("@AM_EMAIL", SqlDbType.VarChar).Value = txtEmailAdd;
    sqlcmd.Parameters.Add("@AM_EMPNOTES", SqlDbType.VarChar).Value = txtEmpNotes.Text;
    sqlcmd.Parameters.Add("@AM_EMPSTATUS", SqlDbType.VarChar).Value = lstStatus.SelectedItem.Value;
    sqlcmd.Parameters.Add("@AM_FIRSTNAME", SqlDbType.VarChar).Value = txtFirstName.Text;
    sqlcmd.Parameters.Add("@AM_JOBRESPONSIBLITY", SqlDbType.VarChar).Value = txtJobResp.Text;
    sqlcmd.Parameters.Add("@AM_LASTNAME", SqlDbType.VarChar).Value = txtLastName.Text;
    sqlcmd.Parameters.Add("@AM_MIDDLENAME", SqlDbType.VarChar).Value = txtMidName.Text;
    sqlcmd.Parameters.Add("@AM_PHONEEXT", SqlDbType.Int).Value = txtPhoneExt.Text;
    sqlcmd.Parameters.Add("@AM_POSITION", SqlDbType.VarChar).Value = txtPosition.Text;
    sqlcmd.Parameters.Add("@AM_MODIFY_RIGHTS", SqlDbType.VarChar).Value = lstModify.SelectedItem.Value;

    sqlconn.Open();
    sqlcmd.ExecuteNonQuery();
    sqlconn.Close();

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    My guess is that it's one of the lines trying to assign a string value to an int parameter:

    sqlcmd.Parameters.Add("@AM_EMPID", SqlDbType.Int).Value = txtEmpID.Text;
    sqlcmd.Parameters.Add("@AM_PHONEEXT", SqlDbType.Int).Value = txtPhoneExt.Text;

    You might try changing those lines to something like:

    ...Value = CInt(txtEmpID.Text)

    Also, make sure the textboxes do indeed contain numeric values.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jun 2007
    Location
    San Francisco
    Posts
    2
    I had the same error message. I checked for the INT columns in my database and found out that I was trying to push a String value into a Int column in my database.

    Thanks!

Similar Threads

  1. Now "they" says Stateful Object Powerful ??
    By Hendry in forum Enterprise
    Replies: 3
    Last Post: 11-18-2003, 01:20 PM
  2. Replies: 7
    Last Post: 10-24-2002, 06:33 AM
  3. Replies: 0
    Last Post: 08-08-2002, 05:56 AM
  4. Even C++ had this much right...
    By Derek Mooney in forum .NET
    Replies: 94
    Last Post: 10-29-2001, 08:44 PM
  5. not quite off-topic
    By Jay Robinson in forum authorevents.patrick
    Replies: 1
    Last Post: 09-05-2000, 05:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links