Solved

VB.Net - DataTable One Row

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Allow User To Arrange Columns At Datagridview 3 24
C# Single Form 8 42
Help with Syntax 9 36
.NET tools for adding thread safety to a web app? 3 31
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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