Need to get empty datatable in .net with database table schema

前端 未结 10 838
闹比i
闹比i 2021-02-07 04:40

What is the best way to create an Empty DataTable object with the schema of a sql server table?

10条回答
  •  梦毁少年i
    2021-02-07 05:16

    You can always create your own:

            DataTable table = new DataTable("TableName");
    
            table.Columns.Add(new DataColumn("Col1", typeof(int)));
            table.Columns.Add(new DataColumn("Col2", typeof(int)));
            table.Columns.Add(new DataColumn("Col3", typeof(string)));
            table.Columns.Add(new DataColumn("Col4", typeof(int)));
            table.Columns.Add(new DataColumn("Col5", typeof(string)));
    

    The obvious draw back being that you will have to update your code whenever the database schema changes.

提交回复
热议问题