Monday, February 18, 2013
C# Not Null Value From Table Row
public class NotNullValueFromTableRow
{
private DataRow dr;
public NotNullValueFromTableRow(DataRow dataRow)
{
dr = dataRow;
}
public object get<T>(string ColumnName)
{
if (dr.Table.Columns.Contains(ColumnName))
if (dr[ColumnName] != DBNull.Value)
{
if (typeof(T) == typeof(string))
return dr[ColumnName].ToString();
return (T)dr[ColumnName];
}
if (typeof(T) == typeof(string))
return string.Empty;
return default(T);
}
}
Example:
DataRow dRow = dt.Rows[0];
NotNullValueFromTableRow notNull = new NotNullValueFromTableRow(dRow);
string Address = (string)notNull.get<string>("ClientAddress");
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment