Pro100 Pro100 - 8 months ago 35
C# Question

Set value of each DataTable row in specific column

I'm having some problem while trying to set column value.

I'v had a dataTable which get some values from SQL and then im adding two new columns by :

dataTable.Columns.Add("dest", typeof(int));

dataTable.Columns.Add("amount", typeof(int));

Which works great but now i want to put 0 in every row in column name dest - and later user will edit this, and then i want to set amount value as

amount = all(this column is in dataTable before I add these 2 columns) + dest;

int columnNumber = 5; //Put your column X number here

for (int i = 0; i < yourDataTable.Rows.Count; i++)
    yourDataTable.Rows[i][columnNumber] = "0";