Loading a DataSet with table definitions & relations (but not data) from SQL Server

.net sql sqlbulkcopy

Question

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.

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.

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?

If not, what approach would you recommend?

Accepted Answer

You can use DataAdapter.FillSchema.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow