读取并检查.csv文件,然后将其上传到sql server 2008 r2
我有一个页面,其中有一个文件上传选项,我必须在其中上传/导入 csv 文件。我想做的是检查上传的文件格式是否正确,例如如果上传了 csv 文件以外的任何文件,系统应该给出错误消息。另外,我需要做的是检查 csv 文件的某些字段,例如 csv 文件中应该有一些必填字段,例如名称、邮政编码,如何检查这些字段是否不为空。执行这些任务后,系统应自动将 csv 文件上传到 sql sever 2008。任何想法或教程...将不胜感激。
I have got a page in which there is a file upload option where I have to upload/import the csv file. What I want to do is to check if the correct format of file is uploaded for instance if any other than csv file is uploaded, the system should give an error message. Also what I need to do is to check certain fields of the csv file for instance there are some mandatory fields in the csv file which should be there like name , postcode, How can I check that these fields are not empty . After performing these task, the system should automatically upload the csv file onto the sql sever 2008. Any ideas or tutorial ... will be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看此线程:
Parsing CSV files in C#, with header
我相信这会让您可以根据需要提取它,然后轻松地将其推入 SQL Server 中的表中。
Check out this thread:
Parsing CSV files in C#, with header
I believe this will let you extract it as you want and then easily shove it into a table in SQL Server.
尝试使用Oledb。这个codenippet可以帮助您将csv文件读入数据表中,该数据表应该很容易转储到数据库中。
try using Oledb. this codesnippet helps you read your csv file into a datatable which should be pretty easy to dump to a database.
在 codeproject.com 上查看 快速 CSV 阅读器
另一种选择是使用SSIS。
Check out the fast CSV reader over at codeproject.com
Another option would be to use SSIS.