Use this:
textBox1.Text = OpenFileDialog.SafeFileName;
string constr = Path.GetExtension(fd);
if(constr == ".xlsx")
{
constr = @"Provider=Microsoft.Jet.OLEDB.12.0;Data Source= '" + textBox1.Text + "';Extended Properties='Excel 12.0;HDR=Yes;'";
}
else if(constr == ".xls")
{
constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" + textBox1.Text + "';Extended Properties='Excel 4.0;HDR=Yes;'";
}