Solved

VB.Net - DataTable One Row

Posted on 2013-02-01
3
378 Views
Last Modified: 2013-02-01
Good Day Experts!

I have a DataTable only contains 1 record.  In the past, I have only used for each loop to process the DataTable.  

For Each sqlRS In sqlRStbl.Rows

Next

How can I just get the row from the DataTable?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
3 Comments
 
LVL 39

Accepted Solution

by:
Kyle Abrahams earned 100 total points
Comment Utility
if SqlRStbl.Rows.Count > 0 then  'ensure there is a row
     sqlRStbl.Rows(0)  (use [0] insead of (0) in C#)
else
    'WOULD HAVE THROWN AN ERROR.  REPORT IT.
end if
0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 100 total points
Comment Utility
does this loop give you errors?

For Each sqlRS In sqlRStbl.Rows

Next


It shouldn't. If it does, do like ged325 suggested:

Dim dr as DataRow
dr=sqlRStbl.NewRow()
If sqlRStbl.Rows.Count > 0 Then
      dr=sqlRStbl.Rows(0)
End If
 

Open in new window


I was not sure where you wanted to store the results so i used a DataRow
0
 

Author Comment

by:Jimbo99999
Comment Utility
Thanks for replying. I was not getting an error with the loop.  I had always processed DataTables with a ForEach loop.  But this DataTable is only being populated with 1 row of data.  I just never knew how to interrogate the DataTable for only 1 row.

 This all stems from when I was using a DataReader that I couldn't close before calling a subroutine.  I passed the subroutine the connection string used by the DataReader and was trying to execute a DataReader on that same connection and was getting an error.  So, I converted the DataReader to a DataTable in the calling routine to alleviate the problem.  

Thanks for the help,
jimbo99999
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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