C# ~ DataTable get column value

public Egg[] GetEggs()
{
string sql = "SELECT TOP 100 * FROM xxxxxxxxxx";
DataTable dt = base.SqlExecuteSelect(sql);
dt.TableName = "ggyy5566";

Egg[] eggs= new Egg[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
Egg egg= new Egg();
egg.Name= dt.Rows[i][1].ToString();
egg.Size= dt.Rows[i][2].ToString();

eggs[i] = egg;
}

return eggs;

}

沒有留言: