Solved

VB.Net - Set value in DataTable row

Posted on 2013-01-29
5
1,701 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
ID: 38831702
Are u using an sql server database?
GL and TotalPaid are on the same table?
0
 

Author Comment

by:Jimbo99999
ID: 38831718
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
ID: 38831770
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
ID: 38831779
Use this in else part

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

Author Comment

by:Jimbo99999
ID: 38832061
That did the trick...no more syntax error.  

Thanks,
jimbo99999
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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