Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1880
  • Last Modified:

VB.Net - Set value in DataTable row

Good Day Experts!

Another day where I have to utilize something in VB.Net that I have not before...hopefully you can help.

I have a DataReader that I am looping through.  Each time around, I need to search for a value from it in a DataTable.  If found in the DataTable, I need to update a value in the DataTable row.  Here is what I have so far:

While sqlRS2rdr.Read()  
          Dim row() As DataRow = tblRS.Select("[GL]='" & sqlRS2rdr.GetValue("GL") & "'")
          If row(0) is Nothing Then

          Else
               'Update row() "TotalPaid" field with sqlRS2rdr.GetValue("TotalPaid")        
          End If
End While

If the GL code value from the DataReader sqlRS2rdr is found in the DataTable tblRS, then update the DataTable tblRS TotalPaid field in the row with the TotalPaid value from the DataReader sqlRS2rdr.  

I cannot seem to find the syntax to accomplish this.  

Can you help?

Thanks,
jimbo99999
0
Jimbo99999
Asked:
Jimbo99999
  • 2
  • 2
1 Solution
 
John (Yiannis) ToutountzoglouCommented:
Are u using an sql server database?
GL and TotalPaid are on the same table?
0
 
Jimbo99999Author Commented:
This is in my VB.Net DataTable.  The DataTable has fields GL,TotalPaid and TotalWeight.  So, when I find the row in the DataTable with the GL from the DataReader then I need to update the TotalPaid in that row.
0
 
John (Yiannis) ToutountzoglouCommented:
ok sorry..
While sqlRS2rdr.Read()   
          Dim row() As DataRow = tblRS.Select("[GL]='" & sqlRS2rdr.GetValue("GL") & "'")
          If row(0) is Nothing Then

          Else
               sqlRS2rdr.Item("TotalPaid")= ........ 
          End If
End While

Open in new window

0
 
CodeCruiserCommented:
Use this in else part

row(0)("TotalPaid") = sqlRS2rdr.GetValue("TotalPaid")
0
 
Jimbo99999Author Commented:
That did the trick...no more syntax error.  

Thanks,
jimbo99999
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now