Solved

VB.Net - Set value in DataTable row

Posted on 2013-01-29
5
1,654 Views
Last Modified: 2013-01-29
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
Comment
Question by:Jimbo99999
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
Are u using an sql server database?
GL and TotalPaid are on the same table?
0
 

Author Comment

by:Jimbo99999
Comment Utility
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
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
Use this in else part

row(0)("TotalPaid") = sqlRS2rdr.GetValue("TotalPaid")
0
 

Author Comment

by:Jimbo99999
Comment Utility
That did the trick...no more syntax error.  

Thanks,
jimbo99999
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now