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;
}
Loading
Guest UserPosted Jan 9, 2009, 12:46 PM
We can't help you if you don't help us.
Guest UserPosted Jan 9, 2009, 12:40 PM
laurens romeijnPosted Jan 9, 2009, 12:26 PM
so i cant do shit with the data. I thought DATASETS can handle every type?!
still after reconnecting and all it worked so i dont know what went wrong the first time
Guest UserPosted Jan 9, 2009, 11:37 AM
Convert it to an integer before trying to store it in the database.
laurens romeijnPosted Jan 9, 2009, 7:12 AM
it works now. So its a weird problem where i still dont know the answer for.