App_Code/fileApi.cs

(开头部分) 11KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;
using System.Data.OleDb;
using System.Text;
using System.Collections;
namespace Utility
{
    public static class fileApi
    {
        #region 读取csv文件

        /// <summary>

        /// 读取CVS文件

        /// </summary>

        /// <param name="path">文件路径</param>

        /// <param name="name">文件名称</param>

        /// <returns>DataTable</returns>

        public static DataTable ReadCVS(string filepath, string filename)
        {

            //string cvsDir = filepath;//要读取的CVS路径

            DataTable dt = new DataTable();

            if (filename.Trim().ToUpper().EndsWith("CSV"))//判断所要读取的扩展名
            {

                string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

                    + filepath + ";Extended Properties='text;HDR=NO;FMT=Delimited'";//有列的读取

                string commandText = "select * from [" + filename + "]";//SQL语句
                OleDbConnection olconn = new OleDbConnection(connStr);

                olconn.Open();

                OleDbDataAdapter odp = new OleDbDataAdapter(commandText, olconn);

                odp.Fill(dt);

                olconn.Close();

                odp.Dispose();

                olconn.Dispose();

            }

            return dt;

后面还有 334 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。