tags:

views:

68

answers:

2

Can anyone please advise where i have gone wrong with the following method / stored proceedure? I keep getting the following error...

**

> Input string was not in a correct

**

This is the Stored proceedure i using and the method.

-- --------------------------------------------------------------------------------

-- Routine DDL
-- --------------------------------------------------------------------------------
DELIMITER $$

CREATE DEFINER=`Admin`@`%` PROCEDURE `test`(
        IN  p_idExceptionLog                INT(32)       , 
        IN  p_ExceptionDate                 DATETIME      , 
        IN  p_User                          VARCHAR(45)   , 
        IN  p_ExceptionMessage              VARCHAR(4000)  

     )
BEGIN 

    INSERT INTO ExceptionLog
         (
           id                    , 
           Date                  , 
           User                  , 
           Message                                      
         )
    VALUES 
         ( 
           p_idExceptionLog                    , 
           p_ExceptionDate                     , 
           p_User                              , 
           p_ExceptionMessage                    
         ) ; 
END

  private void showErrorBox(String errorMsg, MessageBoxButtons btnokshow)
    {

        MessageBox.Show(errorMsg, "FS Manager Error", MessageBoxButtons.OK);

        // write to DB

        string username = System.Environment.UserName.ToString();
        string timestamp = DateTime.Now.ToString();

          // Locals
        MySqlConnection NasDB = null;
    //    MySqlCommand inputError1 = new MySqlCommand();
        MySqlCommand inputError = null;
               int rows = 0;
        string spName = "test";

        try
        {
            //Instantiate the DB connection setting the conn string
            using (NasDB = new MySqlConnection(getConnectionString(ConnectionType.NAS)))
            {
                // Instantiate the command object that will fire the SP.
                using (inputError = new MySqlCommand(spName, NasDB))
                {
                    // Finish setting up the command object
                    inputError.CommandType = CommandType.StoredProcedure;

                    // Set up the SP params.

                    inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("p_idExceptionLog", MySql.Data.MySqlClient.MySqlDbType.Int32, (1)));
                    inputError.Parameters[0].Value = "";

                    inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("p_ExceptionDate", MySql.Data.MySqlClient.MySqlDbType.DateTime, (1)));
                    inputError.Parameters[1].Value = timestamp;

                    inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("p_User", MySql.Data.MySqlClient.MySqlDbType.VarChar, (45)));
                    inputError.Parameters[2].Value = System.Environment.UserName.ToString();

                    inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("p_ExceptionMessage", MySql.Data.MySqlClient.MySqlDbType.VarChar, (4000)));
                    inputError.Parameters[3].Value = errorMsg;

                    // Now that the SP is completely set up and ready to go open the conn and fire the SP.
                    inputError.Connection.Open();
                    rows = inputError.ExecuteNonQuery();

                    // Close ASAP
                    inputError.Connection.Close();
                }
            }

        }
        catch (Exception ex)
        {
            //showErrorBox(ex.ToString());
            throw ex;
        }
    }

Thanks

+1  A: 

Err you are declaring paramter[0] (idExceptionLog) as an Int32 and then setting it to a string in your script? perhaps not setting it will help if it's supposed to be auto-generated or giving it a valid int value if you are manually generating it.

Elf King
I dont think think this is the issue as when run the following on the SP it inputs the data fine however the date format is the other way around.CALL FS.test( '','21/07/2010 16:54:29','steve','messageTest')
Steve
A: 

Worked the problem out.

 private void showErrorBox(String errorMsg, MessageBoxButtons btnokshow)
    {

        MessageBox.Show(errorMsg, "FS Manager Error", MessageBoxButtons.OK);

        // write to DB

        string username = System.Environment.UserName.ToString();
        string timestamp = DateTime.Now.ToString();

          // Locals
        MySqlConnection NasDB = null;
        MySqlCommand inputError = null;
               int rows = 0;
        string spName = "ExceptionInsert";


        try
        {
            //Instantiate the DB connection setting the conn string
            using (NasDB = new MySqlConnection(getConnectionString(ConnectionType.NAS)))
            {
                // Instantiate the command object that will fire the SP.
                using (inputError = new MySqlCommand(spName, NasDB))
                {
                    // Finish setting up the command object
                    inputError.CommandType = CommandType.StoredProcedure;

                    // Set up the SP params.

                    inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("p_idExceptionLog", MySql.Data.MySqlClient.MySqlDbType.Int32, (0)));
                    inputError.Parameters[0].Value = null;

                    inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("p_ExceptionDate", MySql.Data.MySqlClient.MySqlDbType.DateTime, (1)));
                    inputError.Parameters[1].Value = timestamp;

                    inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("p_User", MySql.Data.MySqlClient.MySqlDbType.VarChar, (45)));
                    inputError.Parameters[2].Value = System.Environment.UserName.ToString();

                    inputError.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("p_ExceptionMessage", MySql.Data.MySqlClient.MySqlDbType.VarChar, (4000)));
                    inputError.Parameters[3].Value = errorMsg;

                    // Now that the SP is completely set up and ready to go open the conn and fire the SP.
                    inputError.Connection.Open();
                    rows = inputError.ExecuteNonQuery();

                    // Close ASAP
                    inputError.Connection.Close();
                }
            }

        }
        catch (Exception ex)
        {
            //showErrorBox(ex.ToString());
            throw ex;
        }
    }
Steve