简体   繁体   中英

c# - datatable if one field is null set another value

I have a Datatable.

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

The dt , return list of data like this,

在此处输入图片说明

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

You could try something like this:

dt = ds.Tables[0];
foreach(DataRow row in dt.Rows)
{
   if(row["userId"] == DBNull.Value)
   {
       row["docCount"] = 0;
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM