Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Datatable sequence column

$
0
0
Hi,

I'd like to create a sequence column in my datatable. I have already placed a "1" at [0][0], and then use the following :-

                int SeqNum = Convert.ToInt32(DtSet.Tables[0].Rows[0][0]);
                for (int i = 0; i < DtSet.Tables[0].Rows.Count-1; i++)
                {                  
                    string a1 = DtSet.Tables[0].Rows[i][7].ToString();
                    string a2 = DtSet.Tables[0].Rows[i+1][7].ToString();
                    if (a1 != a2)
                    {
                        DtSet.Tables[0].Rows[i][0] = SeqNum++;
                    }
                    else
                        DtSet.Tables[0].Rows[i][0] = SeqNum;
                }


The value in "column" DtSet.Tables[0].Rows[i][7] is a seven digit number.

The above code works, but I was wondering if there was a way to streamline it?

Thanks in advance.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>