You need a return before your last closing brace. In other words, what happens if your "foreach (DataRowView drv in dv)" loop never gets executed? Your code will fall out of its if/then/else branch and exit your function without an explict return statement.