System.ArgumentException: Input string was not in a correct format.

Jan 9 2009 5:19 AM
hi,
I got a weird problem. In the next code i fill a dataset with the result of a storedproc. if i execute the storedproc nothing is wrong. But at the point i fill the dataset it gives the following error:
System.ArgumentException: Input string was not in a correct format.Couldn't store <8.00> in totaal Column.  Expected type is Int32.

                _sql.Fill(da, result); gives the error.

this is the code:
        public int test(int int1, string string1, ref DataSet result)
        {
            int returnValue = -1; // Set return value to error.
            try
            {
                SQLConnect();

                // Prepair sql command.
                SqlCommand cmd = new SqlCommand("dbo.storedproc", _sql.Connection);
                cmd.CommandType = CommandType.StoredProcedure;

                // Add return parameter value.
                SqlParameter retval = new SqlParameter("returnValue", SqlDbType.Int);
                retval.Direction = ParameterDirection.ReturnValue;
                cmd.Parameters.Add(retval);

                // Create data adapter
                SqlDataAdapter da = new SqlDataAdapter(cmd);

                // Create dataset if not supplied
                if (result == null)
                    result = new DataSet("ds1");

                // Add sql command parameters.
                cmd.Parameters.Add(new SqlParameter("Int1", int1));
                cmd.Parameters.Add(new SqlParameter("String1", string1));

                // Execute sql command.
                _sql.Fill(da, result);

                // Get return value.
                returnValue = (int)cmd.Parameters["returnValue"].Value;
            }
            catch (SqlException sqlEx)
            {
                _sql.LOGtoFILE(string.Format("sql fout opgetreden. sqlEx = '{0}", sqlEx), "test");
            }
            catch (Exception ex)
            {
                _sql.LOGtoFILE(string.Format("fout opgetreden. ex = '{0}", ex), "test");
                //_businessLayer.HandleException(ex, MODULE, "test");
            }
            finally
            {
                _sql.LOGtoFILE("method leave. succeded", "test");
            }

            return returnValue;
        }

Answers (5)