惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
Apple Machine Learning Research
Apple Machine Learning Research
L
LINUX DO - 最新话题
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Visual Studio Blog
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
月光博客
月光博客
博客园 - 叶小钗
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
D
DataBreaches.Net
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog RSS Feed
量子位
美团技术团队
Vercel News
Vercel News
Y
Y Combinator Blog
IT之家
IT之家
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
腾讯CDC
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
博客园 - 司徒正美
N
Netflix TechBlog - Medium
S
Schneier on Security
博客园 - 聂微东
U
Unit 42
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
Latest news
Latest news

博客园 - 爱吃糖豆的猪

Manjaro Samba 设置共享文件夹供Windows访问 【自学Python系列】Python 基础 内部数据结构之列表和元组 【自学Python系列】Python 基础 (字符串,整数,注释) 控制台I/O显示格式化的结果 异步拷贝文件 【超详细教程】使用Windows Live Writer 2012和Office Word 2013 发布文章到博客园全面总结 如何在Directory.GetFiles()方法中设置多个格式呢? C#操作符??和?: ETL 解析 一些概念的随笔(转) 3种思维培养有决策力的孩子 是夫妻就一起把它戒了吧! 一个10年SEO工作者的35个SEO经验 可以让你少奋斗10年的工作经验 如何在一年内拥有十年的工作经验(值得你反复读5遍以上) TreeView 递归选择父节点和子节点 文件操作 C# 中的 ConfigurationManager类引用方法 添加Word,Excel等dll时如何操作。
简单通用的访问CVS的方法
爱吃糖豆的猪 · 2014-12-19 · via 博客园 - 爱吃糖豆的猪
  public DataTable GetCsvData(string filePath, string fileName = "Shipping")
        {
            string path = Path.Combine(filePath, fileName + ".csv");
            string connString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + filePath + ";Extensions=asc,csv,tab,txt;";
            try
            {
                using (OdbcConnection odbcConn = new OdbcConnection(connString))
                {
                    odbcConn.Open();
                    OdbcCommand oleComm = new OdbcCommand();
                    oleComm.Connection = odbcConn;
                    oleComm.CommandText = "select * from [" + fileName + "#csv]";
                    OdbcDataAdapter adapter = new OdbcDataAdapter(oleComm);
                    DataSet ds = new DataSet();
                    adapter.Fill(ds, fileName);
                    return ds.Tables[0];
                    odbcConn.Close();
                }
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
            catch (Exception ex)
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                throw ex;
            }
        }

但是会发现如果源cvs中的列名存在不同的字符:{}/()/[] 会被转换为() 所以会出现无法匹配的问题。

posted on 2014-12-19 14:31  爱吃糖豆的猪  阅读(268)  评论()    收藏  举报