/// <summary>
        /// 读取csv文件
        /// </summary>
        /// <param name="filepath"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
       public  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;ColNameHeader=False;HDR=YES;FMT=Delimited'";//有列的读取
                string commandText = "select * from [" + filename + "]";//SQL语句
                try
                {
                    using (OleDbConnection olconn = new OleDbConnection(connStr)) {
                        olconn.Open();
                        OleDbDataAdapter odp = new OleDbDataAdapter(commandText, olconn);
                        odp.Fill(dt);
                    }
                }
                catch (Exception ex)
                {
                
                }   

            }
            return dt;
        }

posted on 2011-12-16 17:42 sanmao 阅读(764) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

常用链接

留言簿(5)

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜