Solved

Datatable check if exists

Posted on 2009-07-15
3
522 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

688 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