D
Danny Ni
Hi,
I am having problem with the following code snippet:
DataTable dt = getDataFromXLS(@"c:\test\Customers.xls"); //getDataFromXLS
function reads an Excel file and return a sheet as a datatable
for (int i=0;i<dt.Rows.Count;i++)
{
DataRow dr=dt.Rows;
int intCustomerID = (int) dr[0]; //This line fails with error: An
unhandled exception of type 'System.InvalidCastException' occurred
//some other codes go here
}
I looked at the Excel file, the data on the first column are all integers.
But when I tried to debug my application, dr[0].GetType returns
System.Double.
How do I cast it to int?
TIA
I am having problem with the following code snippet:
DataTable dt = getDataFromXLS(@"c:\test\Customers.xls"); //getDataFromXLS
function reads an Excel file and return a sheet as a datatable
for (int i=0;i<dt.Rows.Count;i++)
{
DataRow dr=dt.Rows;
int intCustomerID = (int) dr[0]; //This line fails with error: An
unhandled exception of type 'System.InvalidCastException' occurred
//some other codes go here
}
I looked at the Excel file, the data on the first column are all integers.
But when I tried to debug my application, dr[0].GetType returns
System.Double.
How do I cast it to int?
TIA