日期:2014-05-17 浏览次数:21361 次
public List<string> QueryAuthor(string strID)
{
string sql = "SELECT au_lname FROM authors WHERE au_id = @au_id";
DbParameter param= dbUtility.CreateDbParameter("@au_id", strID);
List<DbParameter> lstParam = new List<DbParameter>();
lstParam.Add(param);
List<string> result = new List<string>();
result = dbUtility.QueryForList<string>(sql, lstParam, CommandType.Text);
return result;
}
public List<T> QueryForList<T>(string sql, IList<DbParameter> parameters, CommandType commandType) where T : new()
{
DataTable data = ExecuteDataTable(sql, parameters, commandType);
return EntityReader.GetEntities<T>(data);
}
public static List<T> GetEntities<T>(DataTable dataTable) where T : new()
{
if (dataTable == null)
{
throw new ArgumentNullException("dataTable");
}
//如果T的类型满足以下条件:字符串、ValueType或者是Nullable<ValueType>
if (typeof(T) == typeof(string) || typeof(T) == typeof(byte[]) || typeof(T).IsValueType)
{
return GetSimpleEntities<T>(dataTable);
}
else
{
return GetComplexEntities<T>(dataTable);
}