如何在vb.net中将批量数据导出/导入到SQL Express 2005
我想制作一个程序模块,将数据库中三个表中的所有记录一次导出到一个文件中(我的意思是不逐行添加,可能像 BULK 那样)。这里我有一些问题
- 是否可以将三个表的记录导出到一个文件中?或者每个表一个文件?
- 在导出或导入时,我不想逐行插入。我想一次完成所有记录。我们可以在编程中做到吗?
- 对于 MS SQL 2005 Express 和 VS 2005,我应该使用哪个数据提供程序?
- 导入到 SQL 2005 Express 怎么样?
I'd like to make a program module that exports all records from three tables in a database into a file at once(I means not adding row by row, maybe like BULK). Here I have some questions
- Is it possible to export records of three tables into a file? Or a file per table?
- At exporting or importing, I don't want to insert row by row. I wanna do all records at once. Can we do it in programming?
- For MS SQL 2005 Express and VS 2005, which data provider should i use?
- How about Importing to SQL 2005 Express?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,您可以使用如下 sql 语句将表导出到 xml 文件中:
SELECT * FROM TABLENAMES FOR XML AUTO,ROOT('filename')
这是一个基于属性的 xml 文件,要使其基于元素,请发送如下命令以下:
SELECT * FROM TABLENAMES FOR XML AUTO,ELEMENTS ROOT('filename')
Actually you can export a table into an xml file with an sql statement like the following:
SELECT * FROM TABLENAMES FOR XML AUTO,ROOT('filename')
this is an attribute based xml file,to make it element based send a command like the following:
SELECT * FROM TABLENAMES FOR XML AUTO,ELEMENTS ROOT('filename')
可以将
Table
导出到文件中吗?是的。它是否以只需几行代码即可执行的方式提供支持?不,不是(除非我极大地忽略了 SQL 或 .NET 的某些部分)。您需要执行一些操作,将数据库中的信息读取到 DataReader、DataSet 或 DataTable 中,然后迭代该信息以获取创建您选择的文件格式。
您的语句如下所示
Select * From Table
您可以在 SQL 上执行
BULK
插入,上面是您在BULK
中读取的方式通过 VB.NET(以及一般的 .NET)连接到 SQLServer,无论您想要使用
SQLClient
命名空间及其各个部分的版本如何:SQLConnection
、<代码>SQL命令It is possible to export a
Table
into a File? Yes. Is it supported in a manner that you can just perform it in a few lines of code? No it isn't (unless I've vastly overlooked some part of SQL or .NET).You will need to do something where you read the information from the database into either a
DataReader
,DataSet
, orDataTable
then iterate over the information to create the file format of your choice.Your statement would look as follows
Select * From Table
You can do
BULK
Inserts on SQL, and the above is how you would read inBULK
To connect to SQLServer through VB.NET (and .NET in general) regardless of the version you will want to use the
SQLClient
namespace and then various parts of that:SQLConnection
,SQLCommand
使用 bcp 导出/导入< /a>
在导出到 Excel 文件时,我们可以将表中的数据放入每张纸中。我还没有使用 bcp 对此进行测试。
Using bcp to Export / Import
In exporting to excel file, we can put data from table per sheet. I haven't tested this by using bcp.