zoukankan      html  css  js  c++  java
  • C#读取EXCEL数据

    #region set connection
       string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+this.txtPath.Text+";Extended Properties=Excel 8.0;";
       myDataReader = null;
      craboDbConnection = new OleDbConnection(strConn);
       OleDbCommand myOleDbCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", myOleDbConnection);
       #endregion

       try
       {
        myOleDbConnection.Open();
        myDataReader = myOleDbCommand.ExecuteReader();
        while (myDataReader.Read())
        {
           this.txtSeq.Text=Convert.ToString(myDataReader.GetValue(0));//列1
    this.txtName.Text=Convert.ToString(myDataReader.GetValue(1));//列2
           this.txtPIN.Text=Convert.ToString(myDataReader.GetValue(2));//列3
        }
    }
       #region Catch
       catch(System.Threading.ThreadAbortException e)
       {
        System.Threading.Thread.ResetAbort();
        this.lblResult.Text = "线程被中断..."+e.Message;
       }
       catch(Exception ex)
       {
        System.Windows.Forms.MessageBox.Show(ex.ToString());
       }
       finally
       {
        // Always call Close when done reading.
        if (myDataReader != null)
         myDataReader.Close();

        // Close the connection when done with it.
        if (craboDbConnection!=null && craboDbConnection.State == ConnectionState.Open)
         craboDbConnection.Close();

        if(webResponse!=null)
         webResponse.Close();
       }
       #endregion

    感谢来访,共同学习!
  • 相关阅读:
    彻底理解cookie,session,token
    IP 别名和辅助 IP 地址
    1 构建Mysql+heartbeat+DRBD+LVS集群应用系统系列之DRBD的搭建
    centos配置DNS和ip
    centos的安装和下载
    activemq的学习
    mongodb的分片
    MongoDB的安装
    分布式事务中的三种解决方案详解(转载)
    redis中redis.conf配置文件解析
  • 原文地址:https://www.cnblogs.com/dingxiaowei/p/3058798.html
Copyright © 2011-2022 走看看