1

I have a Datatable.

using (DataSet ds = new DataSet())
{
    da.Fill(ds);
    dt = ds.Tables[0];
}

The dt, return list of data like this,

enter image description here

From this image, when UserId is DBnull then I want to set docCount equl to 0. How can I do that?

1
  • You can set the default value from sql query too Commented Nov 11, 2016 at 19:01

1 Answer 1

2

You could try something like this:

dt = ds.Tables[0];
foreach(DataRow row in dt.Rows)
{
   if(row["userId"] == DBNull.Value)
   {
       row["docCount"] = 0;
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

You should DBNull.Value instead of null

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.