Hi,
suppose you have an excel sheet contains data in the following format
<br />
ID ISBN Date<br />
1 0273600796 10/1/2011<br />
2 0071162070 10/1/2011<br />
3 0071162070 10/15/2011<br />
4 0070522235 10/15/2011<br />
5 0070527105 11/1/2011<br />
6 0070577277 11/1/2011<br />
7 007024801x 11/15/2011<br />
8 0071164278 12/1/2011<br />
9 0071140654 12/1/2011<br />
saved in excel file named "OutOfPrint.xls"
you can use the following code snip to read this file into datagridview
DbProviderFactory factory =
DbProviderFactories.GetFactory("System.Data.OleDb");
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=OutOfPrint.xlsx;Extended Properties=
""Excel 8.0;HDR=YES;""";
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT ID,ISBN,Date FROM [OutofPrint$]";
connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
gvOutofPrint.Rows.Add(dr["ID"], dr["ISBN"],dr["Date"]);
}
}
}
}
good luck