将CSV文件导入到SQL Server [英] Importing CSV file to Sql server

查看:573
本文介绍了将CSV文件导入到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用c#进行构建和应用,它将从不同的源上载单个csv文件,并将其映射到sql server数据库中的约4个表.有人可以帮我吗……整个事情真的很新

I wish to build and application with c# that will upload a single csv file from different source and map it to about 4 tables in sql server database. Can some one help me pls...am really new in the whole stuff

推荐答案

这应该很简单,您有很多选择它.

1. CSV将具有特定的格式,该格式将映射到您的表.

1.首先,您需要确定如何将CSV上载到可以传递到Sql Server的对象结构中.这里有很多选择
一个.您可以将CSV视为数据源,然后将其上传到数据集或对象数据源中.
b.您可以编写自定义DTO,手动解析文件,然后将其转换为所需的对象列表.

2.接下来,您将必须将该数据批量传输到SP,或者如果您不想使用SP,则多次调用插入查询.在这里,您可以使用表值参数,将实体转换为XML并发送以进行批量更新,或一次插入一行

就这样...

如果您不太习惯C#,则可以使用SSIS向导,该向导将允许您通过拖放来完成相同的工作.
This should be very simple to do and you have a whole bunch of options to do it.

1. The CSV will have a specific format, which will map to your tables.

1. First you need to decide how you will upload the CSV into an object structure which can be passed to the Sql Server. There are a bunch of options here
a. You can treat your CSV as a data source and upload it into a Data Set or object data source
b. You can write a custom DTO, parse the file manually and then convert it into your desired list of objects.

2. Next you will have to transfer this data in bulk to the SP or if you dont want to use a SP then call an insert query multiple times. Here you can use Table value parameters, Convert your entity to XML and send it for bulk update or insert one row at a time

Thats it...

In case you are not so hung up on C# then you may use SSIS wizards which will allow you to do the same job with drag and drops


您可以使用以下声明:

You can do this from T-SQL using the below statement:

bulk insert [dbo].[Courses]
from 'C:\Courses.csv'
with (fieldterminator = ',', rowterminator = '\n')
go




有关其他信息,请访问:将CSV文件导入SQL服务器




For additional info go to: Import a CSV File to SQL Server


这篇关于将CSV文件导入到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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