سلام دوستان کسی میدونه مشکل ای کد چیه؟


DataGridView dgvd1;


string filename;


string ssheet;


string cs = "";



privatevoid button5_Click(object sender, EventArgs e)

{

dgvd1 = dgvd1;



DialogResult d = openFileDialog1.ShowDialog();


if (d == DialogResult.OK)

{

filename = openFileDialog1.FileName;

}



if (System.IO.Path.GetExtension(filename) == ".xlsx")

{



//for office 2007 or higher


cs =
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + ";Extended Properties='Excel 13.0;'";


}



else

{



//for office 2003


cs =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties='Excel 8.0;'";


}



try

{


OleDbConnection cdn = newOleDbConnection(cs);



if (!System.IO.File.Exists(filename))

{



MessageBox.Show("Not Found!");


}



OleDbDataAdapter adapter = newOleDbDataAdapter("Select * From [" + ssheet + "$]", cs);



DataSet ds = newDataSet();


adapter.Fill(ds);


dgvd.DataSource = ds.Tables[0];


}



catch (Exception ex)

{



MessageBox.Show(ex.Message);


}

}