After we retrieve data from database, typically we will have a datareader object. We can leverage on the method below to convert dr value to match with the data type in object class.
protected T GetDataObjectValue
{
int i = dr.GetOrdinal(columnName);
if (!dr.IsDBNull(i))
return (T)dr.GetValue(i);
else
return default(T);
}
Next, we can build a function to load the value into object class like below:
obj.ID = base.GetDataValue
If required, we can add the object into a object List.
No comments:
Post a Comment