How to add identity column to datatable using c#

前端 未结 6 1213
逝去的感伤
逝去的感伤 2020-12-16 18:37

How to add identity column to datatable using c#. Im using Sql compact server.

6条回答
  •  星月不相逢
    2020-12-16 19:32

     DataTable table = new DataTable("table");
    
    
    DataColumn dc= table.Columns.Add("id", typeof(int));
            dc.AutoIncrement=true;
            dc.AutoIncrementSeed = 1;
            dc.AutoIncrementStep = 1;
    
    // Add the new column name in DataTable
    
    table.Columns.Add("name",typeof(string));
    
        table.Rows.Add(null, "A");
        table.Rows.Add(null, "B");
        table.Rows.Add(null, "C");
    

提交回复
热议问题