Friday, 14 December 2012

Excel Heders collected using OLEDB

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
                                      Data Source=" + fileName + @";Extended Properties=""Excel 8.0;HDR=NO;""";
string CreateCommand = "SELECT * FROM [Sheet1$]";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand(CreateCommand, conn);
//   cmd.ExecuteNonQuery();
DbDataReader dr= cmd.ExecuteReader();
int i = 0;
while (dr.Read())
{
    string ab = dr.GetValue(i).ToString();
    MessageBox.Show(ab);
    i++;
}

No comments:

Post a Comment