Solved

Datatable check if exists

Posted on 2009-07-15
3
519 Views
Last Modified: 2012-05-07
How can I check if a datatable exists - am trying to use the below but fails when the table is empty

                if (ds.Tables[2].Rows.Count > 0)
In c#
0
Comment
Question by:tbaseflug
[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
  • 2
3 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 24860315
are you sure that ds.Tables[2] is there

check for

ds.Tables[2] == null
0
 
LVL 15

Accepted Solution

by:
jinal earned 500 total points
ID: 24860334
if(ds.Tables.Count > 2)
{
if(ds.Tables[2] != null && ds.Tables[2].Rows.Count > 0)
{
}
}
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24860810
so just b/c i didn't layout the entire code i get stiffed.

rock on.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

737 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