这妞不错!

会有那么一天...

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
        using System;
        using System.Data;
        using System.Data.OleDb;
        using System.Windows.Forms;


        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=D:\\723\\文档\\客户.xlsx;Extended Properties=Excel 8.0"; 
                //string strCon = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = D:\\0723\\文档\\客户.xlsx;Extended Properties=Excel 8.0";
                OleDbConnection myConn = new OleDbConnection(strCon);
                string strCom = "SELECT * FROM [Sheet1$] ";
                myConn.Open();
                OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);

DataSet myDataSet
= new DataSet(); myCommand.Fill(myDataSet, "[Sheet1$]"); myConn.Close(); for (int i = 0; i < myDataSet.Tables[0].Rows.Count; i++) { if (!string.IsNullOrEmpty(myDataSet.Tables[0].Rows[i]["CODE"].ToString())) { string code = ""; string name = ""; code = "0,'" + myDataSet.Tables[0].Rows[i]["CODE"] + "',"; name = "'" + myDataSet.Tables[0].Rows[i]["NAME"] + "') "; } } string ss = ""; } catch (Exception ex) {
} }

 

需要读取Excel:

读取出的结果集:

 

  

posted on 2014-07-25 19:55  这妞不错  阅读(871)  评论(0编辑  收藏  举报