xls。.aspx读取方式

private void Button1_Click(object sender, System.EventArgs e)
  {
   string strPath="c:\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";

   File1.PostedFile.SaveAs(strPath);

   string mystring="Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '"+ strPath +"';Extended Properties=Excel 8.0";

   OleDbConnection cnnxls = new OleDbConnection (mystring);

   OleDbDataAdapter myDa =new OleDbDataAdapter("select * from [现货$]",cnnxls);

   DataSet myDs =new DataSet();

   myDa.Fill(myDs);

   DataGrid1.DataSource=myDs.Tables[0];

   DataGrid1.DataBind();

  }

posted @ 2008-07-15 14:50  彭成刚  阅读(294)  评论(0编辑  收藏  举报