Understanding DataTable and linq

Asked 1 years ago, Updated 1 years ago, 77 views

Thank you for taking care of me.

string cmdQuery="SELECT* FROM TableA";
            using(DataTableTableA=newDataTable())
            using(OleDbCommand cmd=newOleDbCommand(cmdQuery,conn))
            using(OleDbDataAdapter=newOleDbDataAdapter(comd)){

                adapter.Fill (TableA);
                vartest = from a in TableA
                          group by new {a.ID, a.Date, a.No} intog
                          select new { 
                          id = a.ID
                          Date = a.Date
                          };
            }

I wanted to group the retrieved tableA with linq, but I couldn't find the implementation of the dataTable query pattern."The ""groupby"" could not be found."
I would appreciate it if you could tell me how to avoid it.

c# sql linq

2022-09-30 19:54

1 Answers

If you want to use LINQ for DataTable, refer to DataTableExtensions.AsEnumerable and the DataTableExtensions.AsEnumerable and methods.Use the https://msdn.microsoft.com/ja-jp/library/system.data.datarowextensions(v=vs.100).aspx"rel="nofollow noreferrer">DataRowExtensions.Field<T> method.

 from a in TableA.AsEnumerable()
group by new {
    ID = a. Field <string > ("ID"),
    Date = a. Field <string > ("Date"),
    No = a. Field <string > ("No")
}


2022-09-30 19:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.