• 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

  • 相关阅读:
    GetIPAddress——获得本地IP地址信息
    NetTime——c++实现计算机时间与网络时间的更新
    redis 面试
    jstat命令
    bug 调试
    redis & memcache
    Java进阶知识点:不要只会写synchronized
    Java进阶知识点:并发容器背后的设计理念
    Java进阶知识点:服务端高并发的基石
    Java进阶知识点:不可变对象与并发
  • 原文地址:https://www.cnblogs.com/java20130723/p/3211516.html
Copyright © 2020-2023  润新知