LINQ to DataSets - DataSet Loading Examples


.NET Framework 4.0
LINQ to DataSets, DataSet Loading Examples
Desktop
en-US
6/28/2011

Introduction

This sample shows different DataSet Loading Examples

Building the Sample

  1. Open the Program.cs
  2. Comment or uncomment the desired samples
  3. Press Ctrl + F5

Screenshot

Sample Code

C#
Edit|Remove
            public void DataSetLinq109() 
            { 
 
                var customers = testDS.Tables["Customers"].AsEnumerable(); 
                var orders = testDS.Tables["Orders"].AsEnumerable(); 
 
                var smallOrders = 
                    from c in customers 
                    from o in orders 
                    where c.Field<string>("CustomerID") == o.Field<string>("CustomerID") && 
                        o.Field<decimal>("Total") < 500.00M 
                    select new { CustomerID = (string)c["CustomerID"], OrderID = (int)o["OrderID"], Total = (decimal)o["Total"] }; 
 
                DataTable myOrders = new DataTable(); 
                myOrders.Columns.Add("CustomerID"typeof(string)); 
                myOrders.Columns.Add("OrderID"typeof(int)); 
                myOrders.Columns.Add("Total"typeof(decimal)); 
 
                foreach (var result in smallOrders.Take(10)) 
                { 
                    myOrders.Rows.Add(new object[] { result.CustomerID, result.OrderID, result.Total }); 
                } 
 
                PrettyPrintDataTable(myOrders); 
            }

Source Code Files

More Information

For more information, see: