日期:2014-05-17  浏览次数:20419 次

.net读取excel问题
怎样读取excel中34到44行的数据,但是excel中又没有唯一标识,该怎么写sql语句。

------最佳解决方案--------------------
读出Excel,到datatable。然后判断datatable的行数不就可以了。

   /// <summary>
        /// 连接Excel
        /// </summary>
        /// <returns></returns>
        private OleDbConnection excelConn(string path)
        {
            OleDbConnection Conn = null;
            string excelConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path.ToString().Trim() + ";" + "Extended Properties='Excel 8.0;hdr=no;IMEX=1'";
            Conn = new OleDbConnection(excelConn);
            return Conn;
        }

 public string ReadExcelToTempTable(string FName)
        {
            OleDbConnection connExcel = excelConn(FName);
            string Error = "";
            try
            {
                DataTable dt = new DataTable();

                               connExcel.Open();

                              string strCom = " SELECT * FROM [" + tableName + "]";///SQL操作语句,就是说:取得所有数据从Content
                OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, connExcel);
                DataSet myDataSet = new DataSet();///建立新的数据集myDataSet
                myCommand.Fill(myDataSet);///填充数据集

                dt = myDataSet.Tables[0];//Exceltable

               return Error;

            }
            catch (System.Exception e)
            {
                return e.ToString();
          &