Solved

Object Must Implement IConvertible.   ------ Error.

Posted on 2004-04-08
3
612 Views
Last Modified: 2008-03-06
I am constantly getting this error, how ever i implement or change my code.

the error is "Object must Implement IConvertible"

Dont know how to solve, it. I am getting this error at the last line. SqlCmd.ExecuteNonQuery();


Any Ideas.


Here is the Code, Cut and paste to VS.NET.            


                                  #region public static LogErrorToSqlServer
            static public void LogErrorToSQLServer(
                                          int errorCode,
                                          string errorSource,
                                          string errorCulture,
                                          string errorMessage)
            {
                  SqlConnection SqlConn = null;
                  SqlCommand SqlCmd = null;
                  
                  try
                  {
                        SqlConn = new SqlConnection(Common.DataBaseConnectionString);
                        SqlCmd = new SqlCommand("spInsertError",SqlConn);
                        SqlCmd.CommandType = CommandType.StoredProcedure;
                        
                        SqlParameter paramServer = new SqlParameter("@Server",SqlDbType.VarChar,8);
                        paramServer.Value = System.Web.HttpContext.Current.Server.MachineName;
                        paramServer.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramServer);
                  
                        SqlParameter paramPageURL = new SqlParameter("@PageURL",SqlDbType.VarChar,127);
                        paramPageURL.Value = System.Web.HttpContext.Current.Request.Url;
                        paramPageURL.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramPageURL);

                        SqlParameter paramQueryString = new SqlParameter("@QueryString",SqlDbType.VarChar,127);
                        paramQueryString.Value = System.Web.HttpContext.Current.Request.QueryString;
                        paramQueryString.Direction  = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramQueryString);

                        SqlParameter paramSource = new SqlParameter("@ErrorSource",SqlDbType.VarChar,32);
                        paramSource.Value = errorSource;
                        paramSource.Direction  = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramSource);

                        SqlParameter paramCode = new SqlParameter("@ErrorCode",SqlDbType.Int,4);
                        paramCode.Value = errorCode;
                        paramCode.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramCode);

                        SqlParameter paramCulture = new SqlParameter("@ErrorCulture",SqlDbType.VarChar,8);
                        paramCulture.Value = errorCulture;
                        paramCulture.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramCulture);

                        SqlParameter paramMessage = new  SqlParameter("@ErrorMessage",SqlDbType.VarChar,512);
                        paramMessage.Value = errorMessage;
                        paramMessage.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramMessage);

                        SqlConn.Open();
                        SqlCmd.ExecuteNonQuery();
                  }
                  catch (Exception ex)
                  {
                        ex.ToString();
                  }
                  finally
                  {
                        
                        if (SqlCmd != null) SqlCmd.Dispose();
                        if (SqlConn != null) { if (SqlConn.State != System.Data.ConnectionState.Closed) SqlConn.Close(); SqlConn.Dispose(); }
                  }
            }
            #endregion
0
Comment
Question by:steve_mick972
  • 2
3 Comments
 
LVL 12

Assisted Solution

by:dfiala13
dfiala13 earned 100 total points
ID: 10789090
In this case one of your parameters is not the type you expect.  Double check the signature on your stored proc. Could also be some funky characters in your query string param.  Brute force case, strip down to one param and add them in until one breaks.
0
 
LVL 22

Accepted Solution

by:
_TAD_ earned 400 total points
ID: 10791240


it's also possible that you might be trying to send a C# null value to the stored procedure when the stored procedure might allow a DbNull which is different than a C# null.

But now that I've spit that out, I think it actually throws a different error than what you've provided.


follw dfiala's suggestion and if some reason that doesn't pan out, then look for a data error
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 10791248


Also... if you post the header to the stored procedure someone here may be able to point out your error (if you can't find it).
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

19 Experts available now in Live!

Get 1:1 Help Now