Question

I need to update a datatable in VB.net based on the other column value

| Column_1 |   Column_2 | Column_3 |
___________ ____________ ____________
|    2     |    1       |           |
___________ ____________ ____________
|    5     |    3       |           |
___________ ____________ ____________
|    4     |    2       |           |
___________ ____________ ____________
|    1     |    7       |           |
___________ ____________ ____________
|    8     |    9       |           |
___________ ____________ ____________

What i need is for column1 value 5 , i need column 3 to be 1 and for the remaining row it should be zero.

What i have tried is

Dim CandidateRow As DataRow
CandidateRow = datatable.select("Column_1" = & rbl.selectedvalue).FirstOrDefault  ' datatable value here rbl.selected value would return 5
CandidateRow("Column_3") = 1

It is not updating the Datatable.

So what can be done to perform it

Was it helpful?

Solution

try below c# code and convert it to vb.net

foreach(DataRow row in table)
    {
       if(row["Column_1"]!=null and row["Column_1"].ToString()=="5")
         {
            row["Column_3"]=1;
         }
       else
         {
           row["Column_3"]=0;
         }
    }
//call AcceptChanges() to persist changes made.
table. AcceptChanges();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top