CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

从微软网站上COPY了这个程序读excel不知道错在哪里

楼主jaking()2005-06-01 17:51:41 在 .NET技术 / C# 提问

using   System;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Data;  
  using   System.Data.OleDb;  
  using   System.Drawing;  
  using   System.Web;  
  using   System.Web.SessionState;  
  using   System.Web.UI;  
  using   System.Web.UI.WebControls;  
  using   System.Web.UI.HtmlControls;  
   
  namespace   WebApplication4  
  {  
  ///   <summary>  
  ///   WebForm1   的摘要说明。  
  ///   </summary>  
  public   class   WebForm1   :   System.Web.UI.Page  
  {  
   
  private   void   Page_Load(object   sender,   System.EventArgs   e)  
  {  
   
  //   parameter   as   appropriate   for   your   environment.  
  String   sConnectionString   =   "Provider=Microsoft.Jet.OLEDB.4.0;"   +  
  "Data   Source="   +   Server.MapPath("../ExcelData.xls")   +   ";"   +  
  "Extended   Properties=Excel   8.0;";  
   
  //   Create   connection   object   by   using   the   preceding   connection   string.  
  OleDbConnection   objConn   =   new   OleDbConnection(sConnectionString);  
   
  //   Open   connection   with   the   database.  
  objConn.Open();  
   
  //   The   code   to   follow   uses   a   SQL   SELECT   command   to   display   the   data   from   the   worksheet.  
   
  //   Create   new   OleDbCommand   to   return   data   from   worksheet.  
  OleDbCommand   objCmdSelect   =new   OleDbCommand("SELECT   *   FROM   myRange1",   objConn);  
   
  //   Create   new   OleDbDataAdapter   that   is   used   to   build   a   DataSet  
  //   based   on   the   preceding   SQL   SELECT   statement.  
  OleDbDataAdapter   objAdapter1   =   new   OleDbDataAdapter();  
   
  //   Pass   the   Select   command   to   the   adapter.  
  objAdapter1.SelectCommand   =   objCmdSelect;  
   
  //   Create   new   DataSet   to   hold   information   from   the   worksheet.  
  DataSet   objDataset1   =   new   DataSet();  
                          objDataset1.Tables.Add("XLData");  
  //   Fill   the   DataSet   with   the   information   from   the   worksheet.  
  objAdapter1.Fill(objDataset1,   "XLData");  
  DataGrid   DataGrid1=new   DataGrid();  
   
  //   Bind   data   to   DataGrid   control.  
  DataGrid1.DataSource   =   objDataset1.Tables[0].DefaultView;  
  DataGrid1.DataBind();  
   
  //   Clean   up   objects.  
  objConn.Close();  
  }  
   
  #region   Web   窗体设计器生成的代码  
  override   protected   void   OnInit(EventArgs   e)  
  {  
  //  
  //   CODEGEN:   该调用是   ASP.NET   Web   窗体设计器所必需的。  
  //  
  InitializeComponent();  
  base.OnInit(e);  
  }  
   
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {          
  this.Load   +=   new   System.EventHandler(this.Page_Load);  
   
  }  
  #endregion  
  }  
  }  
  问题点数:0、回复次数:1Top

1 楼LaoDai_Net(『老代』)回复于 2005-06-01 19:12:06 得分 0

把错误信息贴出来啊Top

相关问题

  • 有谁用过Tidestone Formula One 6.0的外部控件?该控件类似于微软的EXCEL的程序,拥有EXCEL的功能!
  • SDI程序与EXCEL
  • 微软程序员考试题
  • 是微软没这功能? 还是中国人都不会? APS.NET中怎么让Excel程序运行显示出来?
  • excel copy
  • 程序中调用excel!
  • 用vba和excel做程序
  • excel应用程序错误
  • 微软专家:配置为“库应用程序”的COM+应用程序
  • 请微软专家出山---excel问题

关键词

  • datagrid
  • objdataset
  • objadapter
  • objconn
  • worksheet
  • oledbdataadapter
  • oledbcommand
  • dataset
  • ui
  • load

得分解答快速导航

  • 帖主:jaking

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo