?
Solved

VB.Net - DataTable One Row

Posted on 2013-02-01
3
Medium Priority
?
387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 400 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 400 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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