Tuesday 7 May 2013

Find Null/Empty Values in Asp.net Datatable and Replace with Other Values

Try this C# code on datatable to avoid null reference error message...........

for (int i = 0; i < dt.Rows.Count;i++ )
{
for(int j=0;j<dt.Columns.Count;j++)
{
if(string.IsNullOrEmpty(dt.Rows[i][j].ToString()))
{
// Write your Custom Code
dt.Rows[i][j] = "your required value";
}
}
}

No comments:

Post a Comment