HI Friends..i want to import an excel file to DataGridView .In My code its working Fine For all excel sheet that have less number of columns...but its showing error(External table is not in the expected format.) for excel sheet having more number of columns...please help me...my code is below
private void btnbrowse_Click(object sender, EventArgs e)
{
DialogResult dr = this.ofdopen.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
string connectionString = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", ofdopen.FileName);
string query = String.Format("select * from [{0}$]", "Sheet1");
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dataSet = new DataSet();
//DataTable dtbl = new DataTable();
dataAdapter.Fill(dataSet);
dgvMain.DataSource = dataSet.Tables[0];
}
:sad: