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();

  }

---------------------------------------------
彭成刚微博:http://t.sina.com.cn/pengchenggang/
彭彭新浪博客:http://blog.sina.com.cn/zzcn/
彭彭技术博客:http://pengpengsay.cnblogs.com/
彭彭百度博客:http://hi.baidu.com/pengpengsay/
彭彭照片相册:http://zzcn.yupoo.com/

posted on 2008-07-15 14:50 彭成刚 阅读(140) 评论(0) 编辑 收藏