读取.csv,.txt文件并在数据库中插入数据 [英] Read .csv , .txt file and insert data in database

查看:108
本文介绍了读取.csv,.txt文件并在数据库中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想读取.csv,.txt文件并将其插入TABLE特定列,例如表A的列名为CONTENT 。我想以相同的格式插入/检索数据库中的数据。我不确定数据格式是一行还是多行。



先谢谢



我尝试过:



Hi ,

I want to read the .csv , .txt file and insert it into TABLE particular column, e.g table A is having column name "CONTENT". I want insert/retrieve the data to and from database table in same format. I am not sure about data format one line or multiple line.

Thanks in Advance

What I have tried:

public bool ReadFile(string FilePath)
       {
           bool resultflag = false;

           FILE_NAME = FilePath.Substring(FilePath.LastIndexOf('\\') + 1);
           FILE_NAME = FILE_NAME.Substring(0, FILE_NAME.LastIndexOf('.'));

           string strReturn = string.Empty;
           System.Collections.ArrayList arrText = new System.Collections.ArrayList();
           try
           {

               StreamReader objReader = new StreamReader(FilePath);
               string sLine = "";

               while (sLine != null)
               {
                   sLine = objReader.ReadLine();
                   if (sLine != null)
                   {
                       arrText.Add(sLine);
                   }
               }
               objReader.Close();              

               return resultflag;

           }

           catch (Exception ex)
           {
               return false;
           }
       }

推荐答案

Quote:

我想以相同的格式插入/检索数据库中的数据。

I want insert/retrieve the data to and from database table in same format.

为什么?通常 CSV 文件确实提供结构化数据,并且在数据库中重现相同的结构是很自然的。





在任何情况下,什么阻止你在数据库中存储检索到的 CSV 内容?如果您遇到麻烦,请 Google提供帮助 [ ^ ] 。

Why? Usually CSV files do provide structured data and it's natural to reproduce the same structure inside the database.


In any case what stops you in storing retrieved CSV content inside the database? If you have troubles in doing it, Google might provide help[^].


为什么不这么简单呢?请参阅使用OleDb导入文本文件(选项卡,CSV,自定义) [ ^ ]。
Why not do it the easy way? See Using OleDb to Import Text Files (tab, CSV, custom)[^].


这篇关于读取.csv,.txt文件并在数据库中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆