Skip to content

Instantly share code, notes, and snippets.

@mendhak
Created August 16, 2012 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mendhak/3369288 to your computer and use it in GitHub Desktop.
Save mendhak/3369288 to your computer and use it in GitHub Desktop.
Extension method to get value from a field in a datarow
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));
}
}
@sebthesoftwaredeveloper
Copy link

Very clean and useful code. thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment