"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Friday, November 30, 2012

Datatable with auto increment option



Datatable with auto increment option c#


        DataTable dtDuplicatelist = new DataTable();

        DataColumn auto = new DataColumn("AutoID", typeof(System.Int32));
        dtDuplicatelist.Columns.Add(auto);
        auto.AutoIncrement = true;
        auto.AutoIncrementSeed = 1;
        auto.ReadOnly = true;
        auto.Unique = true;


        dtDuplicatelist.Columns.Add("ClientID", typeof(string));
        dtDuplicatelist.Columns.Add("CurrentLoanServicer", typeof(string));
        dtDuplicatelist.Columns.Add("CurrentServicerLoanNo", typeof(string));
        dtDuplicatelist.Columns.Add("NameOfOriginatingLender", typeof(string));
        dtDuplicatelist.Columns.Add("Noofrec", typeof(string));
        dtDuplicatelist.Columns.Add("OriginalLoanNumber", typeof(string));

        dtDuplicatelist.PrimaryKey = new DataColumn[] { auto }; // Setting as primary key Then only it will add autoincrement to the Column
        return dtDuplicatelist;

 
If u had any trouble just ask, Happy to help u :)
Stay Tune... Have a nice day... 'N happy Coding :)

No comments: