I get an annoying NullReferenceException whenever I use the following kind of code
foreach(DataRow row in datatable.Rows)
{
str1 = row[0].ToString();
}
I usually work around this by adding a try catch like so:
foreach(DataRow row in datatable.Rows)
{
try
{
str1 = row[0].ToString();
}
catch (NullReferenceException err)
{
//do nothing
}
But I'm sure there must be something better as this does not look pleasant at all. Thanks in advance.
This post has been edited by lando786: 27 April 2011 - 08:30 AM

New Topic/Question
Reply



MultiQuote






|