InvalidCastException when fill dataset

  • Thread starter Thread starter infmpv00
  • Start date Start date
I

infmpv00

Someone can help me to solve this problem in my code?¿

This is the code:

private static DataSet executeQuery(string strConnectionString, string
strQuery)
{
try
{
DataSet dsResult = new DataSet();
OleDbConnection conn = new OleDbConnection(strConnectionString);
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(strQuery, conn);

adapter.Fill(dsResult);
return dsResult;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
return null;
}
}


This is the exception that I obtain when fill the datase:

[InvalidCastException: The data value could not be converted for
reasons
other than sign mismatch or data overflow. For example, the data was
corrupted in the data store but the row was still retrievable.]


Thanks
 
Hello,

It means that you are trying to insert a value that does not conform to
your field type. This is often seen with date and time formats. You might
check anything that is a string that is going into an integer field also
and cast it into an integer before trying your insert statement. I believe
you may also possibly get this error in Access if your data is longer than
the field allows so you might check the length of your insert data.

Hope this helps you solve the problem.

Best regards,
Rami Saad
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top