1

私は次のListように入力しています:

public List<Functions> ListFunctions(int proj)
   {
      List<Functions> lFunctions = new List<Functions>();
      try
         {
            string sql = "SELECT id, description FROM functios WHERE project = @project ORDER BY description ASC";
            MySqlCommand cmd = new MySqlCommand();
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add(new MySqlParameter("@project", MySqlDbType.Int32)).Value = proj;

            using (MySqlDataReader reader = _dal.ExecutaReader(cmd))
               {
                  while (reader.Read())
                     {
                        lFunctions.Add(new Function
                          {
                            ID = Convert.ToInt32(reader["id"]),
                            Descripton = reader["description"].ToString()
                          });
                      }
                }
            return lFunction;
         }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }  

リストをループして値を取得するにはどうすればよいですか? Descriptionと_ID

次のように、fieldName を正確に取得する方法を知りたいです。

string name = ListFunction["FieldName"].ToString()
4

1 に答える 1

1

返されたリストを列挙するだけです。例えば:

var functions=ListFunctions(0); // For example
foreach(var function in functions)
{
  Console.WriteLine("{0} = {1}",function.ID, function.Description);
}
于 2013-07-08T12:44:29.737 に答える