My datatable consists of a column named "ID". No. The values in this column change. Sometimes this Datatable retrieves 3 identifiers in this identifier column, sometimes 2. Now, if, for example, my datatable has three values like 1,2,3. I want to put these three values in a string and separate them with commas as folows: -
string test= "1,2,3";
If the Datatable has 2 values, the line should be as follows: -
string test= "1,2";
I tried, but in vain. Please help. Thank.
edit: -
DataTable dt=new DataTable;
dt = obj.GetIDs();
for (int i = 0; i < dt.Rows.Count; i++)
{
string test= "What should be here????";
}
change 2
foreach(DataRow dr in dt.Rows)
{
string str = str + "," + Convert.ToString(dr("ID"));
}
@Rajeev :: Tried this ... says dr is a variable, but used as a method. What's wrong?
source
share