Converting a DataTable to an CREATE TABLE + INSERT script for SQL in C#

后端 未结 4 500
暗喜
暗喜 2020-12-09 06:37

I need to generate a TSQL script from a DataTable along with the DATA in it. It\'s not a single insert. Beside that, I need the create the table too (same datatable structur

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 07:00

    Take a look at: Generate SQL INSERT commands programmatically

    Essentially, the code is looping through the DataTable.Columns collection to generate the column list of the INSERT statement. Then it loops through the values of the DataTable to create the parameters with values.

提交回复
热议问题