我收到了「非靜態字段,方法或屬性Skirmer_Final.Nyhed.FK_Nyhed_ID.get」錯誤需要對象引用。我無法弄清楚什麼是錯的。非靜態錯誤,無法找到原因
我的代碼
public class Nyhed
{
public int FK_Status_ID { get; set; }
public int FK_Nyhed_ID { get; set; }
public static List<Nyhed> GetByStatus(int ID, SqlConnection connection)
{
List<Nyhed> result = new List<Nyhed>();
using (var command = new SqlCommand("Select FK_Nyhed_ID from Status_Kan_Se_Nyhed where [email protected]"))
{
command.Connection = connection;
command.Parameters.AddWithValue("id", ID);
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
Nyhed StatusKanSeNyhed = new Nyhed();
StatusKanSeNyhed.FK_Status_ID = ID;
StatusKanSeNyhed.FK_Nyhed_ID = reader.GetInt32(0);
result.Add(StatusKanSeNyhed);
}
}
finally
{
reader.Close();
}
foreach (Nyhed N in result)
{
N.status = Status.GetByID(FK_Status_ID, connection);
N.nyhed = Nyhed.GetByID(FK_Nyhed_ID, connection);
}
}
return result;
}
}
你能看到錯誤?
我是怎麼錯過的。感覺像現在一樣傻 – 2012-02-07 16:56:46