0

suppose there 5 column in my table info(id,loginid,pagename,pagecount,detail). I am executing the query like, select the pagename when loginid=somthing and id =something.But in column that is pagecount(int) and pagename(varchar),I am not putting any thing ,so it consider as null.When execute the query,result shows the column with null value.Query's result move to else part.How to handle with that null value.

if(table.Rows.count == 0)
{
}
else
{
Actually coding.
}
2
  • 1
    your question isn't clear, are you looking for how to check if columns value is null or what? Commented Jul 27, 2011 at 10:05
  • When I am running the query ,geeting output in sql one row with null value.If the value is null still it take one row.So my code move to else part.So how to check the column value is null. Commented Jul 27, 2011 at 10:12

1 Answer 1

1

This is how you check if the column's value is null

if (table.Rows.Count > 0) // if table is not empty
{
       if (Convert.IsDBNull(table.Rows[0]["columnName"])) // It's checking null value for columnName 'columnName' of first row
       {
                    //This column's value is null
       }
       else
       {
                    //column has value other than null
       }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Waqas,Shadow for your reply.Now it is working with [0]["columnname"].I would like to asked u one more that instead of null suppose there is nothing in that column.The column is empty.Then how to handle with that.If I am executing the query empty cell comes,then?I don't know how to handle that.
its even simpler, use table.Rows[0]["columnName"].toString().trim() != string.empty.. but keep in mind that this piece of code will throw exception if the column value is null
and also please mark this as your accepted answer if it helped you in finding what you were looking for....
@Komal, welcome, between would you mind marking my answer as accepted by clicking the 'tick mark' on the left?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.