This code snap will fetch each record from your excel sheet 1 located at D:\ drive and return records as datatable.
public static DataTable GetItemsFromExcel1()
{
DataTable dt = new DataTable();
oleDbConnection excelConnection =
new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;"
+ @"Data Source=D:\YourFile.xls;"
+ @"Extended Properties=""Excel
8.0;HDR=Yes;IMEX=1;""");
excelConnection.Open();
try
{
OleDbDataAdapter dbAdapter =
new OleDbDataAdapter("SELECT * FROM [Sheet1$]", excelConnection);
dbAdapter.Fill(dt);
}
finally
{
excelConnection.Close();
}
return dt;
}
Post Reference: Vikram Aristocratic Elfin Share
public static DataTable GetItemsFromExcel1()
{
DataTable dt = new DataTable();
oleDbConnection excelConnection =
new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;"
+ @"Data Source=D:\YourFile.xls;"
+ @"Extended Properties=""Excel
8.0;HDR=Yes;IMEX=1;""");
excelConnection.Open();
try
{
OleDbDataAdapter dbAdapter =
new OleDbDataAdapter("SELECT * FROM [Sheet1$]", excelConnection);
dbAdapter.Fill(dt);
}
finally
{
excelConnection.Close();
}
return dt;
}
Post Reference: Vikram Aristocratic Elfin Share
No comments:
Post a Comment