Putting datatable comma separated values in a string
<p>My datatable consists of a column named "ID". The no. of values in this column varies.Sometimes this Datatable fetches 3 IDs in that ID column, sometimes 2.
Now if for example, my datatable has three values as 1,2,3. What I want is to put these three values in a string and separate them by commas as folows:-</p>

<pre><code>string test= "1,2,3";
</code></pre>

<p>If Datatable has 2 values, then string should be as follows:-</p>

<pre><code>string test= "1,2";
</code></pre>

<p>I did try but in vain. Please help. Thanks.</p>

<p>edit:-</p>

<pre><code>DataTable dt=new DataTable;
 dt = obj.GetIDs();

                for (int i = 0; i &lt; dt.Rows.Count; i++)
                { 
                string test= "What should be here????";
                }
</code></pre>

<p><strong>edit 2</strong></p>

<pre><code> foreach(DataRow dr in dt.Rows)
            {
                string str = str + "," + Convert.ToString(dr("ID"));

            }
</code></pre>

<p>@Rajeev ::Tried this..it says dr is a variable but used as a method. What's wrong?</p>
