Solved

VB.Net - Set value in DataTable row

Posted on 2013-01-29
5
1,672 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change data in datatable 8 31
Getfiles in vb.net 28 43
Help with concatenating data from one data element to another using VB.NET 3 33
Help with LINQ and XML 10 27
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

13 Experts available now in Live!

Get 1:1 Help Now