c# CSV读入DataSet

 

代码
file="c:\\temp\test.csv";



DataSet ds 
= new DataSet();
        
string filePath = file.Substring(0, file.LastIndexOf("\\"+ 1);
        
using (OleDbConnection conn = new OleDbConnection(string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Text;'", filePath)))
        {
            OleDbDataAdapter adp 
= new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", file.Replace(filePath, "")), conn);
            
try
            {
                adp.Fill(ds, 
"clbm");
            }
            
catch
            {

            }
        }

 

 

posted @ 2010-12-24 11:19  94cool  阅读(607)  评论(0编辑  收藏  举报