0

I am using ASP.NET/C# 4.0 with PetaPoco Micro ORM.

PetaPoco code retrieves a list of Years in a var. Now I want to populate an ASP.NET DropDown Control with the items in this var.

Does PetaPoco provide something to do this in less code? Alternatively, how can I loop through the var and add items in the DropDown?

    var db = new PetaPoco.Database("myConnection");
    var fy = new fy_master();

    string Query = "SELECT fyperiod FROM fy_master ORDER BY fy_id desc";
    var result = db.Execute(Query);
RKh
  • 13,818
  • 46
  • 152
  • 265
  • 1
    You're missing the point of what `var` is. It isn't a type that has it's own interface, it is whatever you assign to it. – Ash Burlaczenko May 24 '12 at 08:22
  • 1
    A `var` is not a type. It's a keyword for when you don't know or don't care about the type, but the system knows the type. It infers it during compile time and with Intellisense you can hover over the var and see what it becomes! – Davio May 24 '12 at 08:23
  • Actually I tried adding a List but that is again an overhead. – RKh May 24 '12 at 08:41

1 Answers1

1

According to the Petapoco Documentation Execute is similar to ExecuteNonQuery which you can't use if you want to select items. You must use Fetch command to return a list of POCOs.

Here is a discussion on populating combo box. You should be able to follow a similar approach to fill in ASP.NET DropDownList

Prashanth Thurairatnam
  • 4,353
  • 2
  • 14
  • 17