try
{
DataSet ds=new DataSet();
string strCon,strCmm;
strCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source =D:/test.xls;Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
strCmm="select distinct * from [Sheet1$]"; //Excel表中左下脚的表明要与[]中一致,绑定时必须关闭相应的Excel表
OleDbConnection oleCnn=new OleDbConnection(strCon);
OleDbCommand oleCmm=new OleDbCommand(strCmm,oleCnn);
OleDbDataAdapter oleDa=new OleDbDataAdapter(oleCmm);
oleDa.Fill(ds,"test");
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}
catch(Exception err)
{
Label1.Text="出错:"+err.Message;
}