Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all,
Here i using business logic that method return dataset. for me that dataset return null. how to check.
For eg:
C#
for (int i = 0; i < dsAccSId1.Tables[0].Rows.Count; i++)
{
  string company = dsAccSId1.Tables[0].Rows[i]["Accid"].ToString();
  string getbill = "Select * from tblbillmaster where company ='" + company + "'";
  DataSet getcomp = dbObj.InlineExecuteDataSet(getbill);
  if (getcomp.Tables[0].Rows.Count > 0)
  {
    ds.Merge(getcomp);
  }
}
return ds;

above example here i merging dataset .if the count not exists then ds should be empty even column not bind.how to resolve this problem.

What I have tried:

here i check null but it no use it will process next step and then i got error table cannot find 0
Posted
Updated 4-Mar-16 17:55pm
v3
Comments
[no name] 4-Mar-16 5:59am    
If you are getting dataset as null then you need to check null(if(getcomp != null)) before performing any action.
VR Karthikeyan 4-Mar-16 5:59am    
Can't understand your question, please improve your question.
Richard Deeming 4-Mar-16 6:18am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Try:
C#
if (getcomp != null && getcomp.Tables.Count > 0)
   {
   ...
   }
But as Richard says: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
Google for "Bobby Tables" and don't just assume it's a joke!
 
Share this answer
 
I had same problem before so what i had used is..
if (dsAccSId1 != null && dsAccSId1.Tables.Count > 0 && dsAccSId1.Tables[0].Rows.Count > 0)
{
	
}

May be this will help you...
 
Share this answer
 
Use the following statement
C#
if (ds.Tables[0].Rows.Count == 0)
{
    //
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900