You must Sign In to post a response.
  • Category: Windows

    Add number column autoincrement in datatable

    To the existing DATATABLE, I want to add identity column as "TaxNo"=> 1,2,3,4,5.....

    Using below code" but I could see new column added without values... Values not getting appending.. Why..
    DataColumn dcAutoNumber = new DataColumn("TaxNo",typeof(int));
    dcAutoNumber.AutoIncrement = true;
    dcAutoNumber.AutoIncrementStep = 1;
    dcAutoNumber.ColumnName = "TaxNo";
    dtTaxiDetails.PrimaryKey = new DataColumn[] { dtTaxiDetails.Columns["id"] };
  • #770090
    Hi Lily,

    I suggest u should use dcAutoNumber.DefaultValue = dtTaxiDetails.Rows.Count + 1

    It will always increase the count with 1 plus the number of rows that exists in the data table.

    I hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "If you can dream it, you can do it."

  • Sign In to post your comments