从SQL Server加载具有表定义和关系(但不是数据)的DataSet

时间:2022-07-23 10:36:51

I'm not an expert with either System.Data nor SQL Server, but have a need to generate a large DataSet then use System.Data.SqlClient.SqlBulkCopy to store the results.

我不是System.Data和SQL Server的专家,但需要生成一个大型DataSet,然后使用System.Data.SqlClient.SqlBulkCopy来存储结果。

The DataSet will consist of about 10 related tables. When SqlBulkCopy transfers the DataSet to SQL Server, my understanding is that rows from the various DataTables will get integrated with the existing SQL tables, maintaining relationships and constraints.

DataSet将包含大约10个相关表。当SqlBulkCopy将DataSet传输到SQL Server时,我的理解是来自各种DataTable的行将与现有SQL表集成,维护关系和约束。

Rather than building DataTables by hand and manually setting relations and constraints, and rather than creating an XML Schema Definition, is there an easy way to load multiple table definitions, constraints, and foreign key definitions from SQL directly into a DataSet?

而不是手动构建DataTables并手动设置关系和约束,而不是创建XML模式定义,是否有一种简单的方法可以将SQL中的多个表定义,约束和外键定义直接加载到DataSet中?

If not, what approach would you recommend?

如果没有,你会推荐什么方法?

1 个解决方案

#1


You can use DataAdapter.FillSchema.

您可以使用DataAdapter.FillSchema。

#1


You can use DataAdapter.FillSchema.

您可以使用DataAdapter.FillSchema。