Solved

VB.Net - DataTable One Row

Posted on 2013-02-01
3
382 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 40

Accepted Solution

by:
Kyle Abrahams earned 100 total points
ID: 38843710
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
ID: 38843848
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
ID: 38843880
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Crystal reports vb.net 2 54
VB.NET (2008) - Refactoring Question 2 24
Get distinct values from excel or comm seperated file 4 32
Need syntax help building hyperlink 2 27
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

831 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