메신저 데이터베이스에서 데이터를 동적으로 가져 오려고합니다. 나는 ...을 heres 내가 여기 DataReader를 사용하여 datas를 얻을 수 있습니다 내 문제는 코드 list<T> select<T>()
방법입니다했습니다목록에 유형을 추가하는 방법 <T> C# 4,0
public list<T> Select<T>()
{
Type type = typeof(T);
...
...
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
try
{
SqlCommand sqlCommand = new SqlCommand(selectCommand, connection);
connection.Open();
SqlDataReader sqlReader = sqlCommand.ExecuteReader();
while (sqlReader.Read())
{
foreach (PropertyInfo property in type.GetProperties())
{
property.SetValue(property.Name,(PropertyInfo)sqlReader[property.Name],null);
}
typeList.Add((T)Convert.ChangeType(type,typeof(T)));
}
sqlReader.Close();
}
catch (Exception ex)
{
string exc = ex.Message;
}
finally
{
connection.Close();
}
}
return typeList;
}
내가 데이터를 얻을 수 있지만 난 그래서 난 내 typelist에 내 유형을 추가 할 수 없습니다 내 타입에 할당 할 수 없습니다 도와주세요
, 당신이 질문을 편집 코드를 선택하고의 코드 버튼을 누릅니다 편집기 (101 \ 010을 가진 편집기). –
코드가 불완전하여 typeList 선언이 누락되었습니다. –