导入Excel数据

private void Bind()
     {
   string connString=String.Format("data source={0};provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0",Server.MapPath("ExcelFiles/chengji.xls"));
   OleDbConnection conn=new OleDbConnection(connString);
   conn.Open();
   OleDbCommand cmd=new OleDbCommand("select * from [sheet1$]",conn);
   OleDbDataReader dataReader=cmd.ExecuteReader();
   DataGrid1.DataSource=dataReader;
   DataGrid1.DataBind();
   conn.Close();
  }
posted on 2007-06-27 20:48  上校  阅读(231)  评论(0编辑  收藏  举报