How to add identity column to datatable using c#

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

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

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 19:31

    You could try something like this maybe?

    private void AddAutoIncrementColumn()
    {
        DataColumn column = new DataColumn();
        column.DataType = System.Type.GetType("System.Int32");
        column.AutoIncrement = true;
        column.AutoIncrementSeed = 1000;
        column.AutoIncrementStep = 10;
    
        // Add the column to a new DataTable.
        DataTable table = new DataTable("table");
        table.Columns.Add(column);
    }
    

提交回复
热议问题