Created
August 16, 2012 10:59
-
-
Save mendhak/3369288 to your computer and use it in GitHub Desktop.
Extension method to get value from a field in a datarow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static T GetValue<T>(this DataRow row, string field) | |
{ | |
if (!row.Table.Columns.Contains(field)) | |
{ | |
return default(T); | |
} | |
else | |
{ | |
return (T)Convert.ChangeType(row[field].ToString(), typeof(T)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very clean and useful code. thank you.