How Do I Load Datatable in C# from Query using QueryAsync RRS feed

  • Question

  • User564995064 posted

    Please forgive my ignorance.  I am picking up where a previous co-worker left off working on a console application in C#.  I can use the following code to get a list of id's but the results come back with attributes of type, url and id.  I need to put a list of just the id's into a datatable.  That way I can loop through each id in the datatable.  How can I do this?

    Task<QueryResult<dynamic>> program_id = client.QueryAsync<dynamic>("SELECT id FROM Programs");

    Tuesday, February 2, 2021 3:28 AM

All replies

  • User1686398519 posted

    Hi rhondadunn, 

    I need to put a list of just the id's into a datatable. 

    "QueryAsync" seems to be your custom method.

    Do you want to take out the value of program_id and add them to the DataTable?

    1. If this is the case, you need to use Task<TResult>.Result Property gets the result value of this Task<TResult>.
      • var value = program_id.Result;
    2. Then you can foreach data and add them to the DataTable.
      • var data=value.ToList();        
        foreach (dynamic item in data){

    3. You can click on the links below to see how to use Datable:
      1. Convert LINQ Query Result to Datatable 
      2. DataTable Examples

    Best Regards,


    Tuesday, February 2, 2021 8:37 AM