How to return an array of class type and fill?

后端 未结 2 749
生来不讨喜
生来不讨喜 2021-01-26 10:39

I have a function which is supposed to return an array of class type.

So from database I picked data and filled datatable. Now from datatable I am picking columns value

2条回答
  •  清歌不尽
    2021-01-26 11:16

    This is only an indirect answer, but: ultimately, the thing you are trying to do is a solved problem, with lots of tools existing to do all the work for you. Since this is a simple scenario, "Dapper" would make this trivial. I'll give a C# example here, as my VB level is read-only:

    List BindGridInfoFunctionalLocation()
    {
        // note: column aliases to match properties on AssetsDto
        var results = connection.Query(@"
    select  FunctionalLocation as 'ASSETTAG',
            EquipmentDescription as 'ASSETDESC',
            Area as 'PARENTTAG',
            EqptType as 'ASSETTYPE'
    from    EngineeringData").AsList();
    
        gv_InfoFunctionalLocation.DataSource = results;
        gv_InfoFunctionalLocation.DataBind()
        return results;
    }
    
    

提交回复
热议问题