我正在尝试循环遍历数据集,如果有 0,我想将其更改为空值或空白,到目前为止我有这个
foreach (DataRow drRow in ds.Tables[0].Rows)
{
//loop through cells in that row
{
//if the value is 0 change to null or blank
}
}
谁能帮我解决这个问题?
最佳答案
当然
foreach (DataRow drRow in ds.Tables[0].Rows)
{
for(int i = 0; i < ds.Tables[0].Columns.Count; i++)
{
int rowValue;
if (int.TryParse(drRow[i].ToString(), out rowValue))
{
if (rowValue == 0)
{
drRow[i] = null;
}
}
}
}
我真的相信没有人仍然使用数据集:(
关于c# - 如何循环遍历数据集并更改数据 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6371570/