Linq and untyped DataSets
As a small update to the previous post - if you don't fancy looking through each table in an untyped dataset then linq is your friend. For instance to join information from two of the yr.no-service tables you can do this:
// Join "time" and "temperature"-tables,
// Get id, temperature, from time and to time
var query =
from time in ds.Tables["time"].AsEnumerable()
join temp in ds.Tables["temperature"].AsEnumerable()
on time.Field<int>("time_id") equals
temp.Field<int>("time_id")
select new
{
TemperatureId = time.Field<int>("time_id"),
Tempearature = temp.Field<string>("value"),
FromTime = time.Field<string>("from"),
ToTime = time.Field<string>("to"),
};
// Simple output
foreach (var tempInfo in query)
{
Console.WriteLine("{0} - {1}:\t{2}",
tempInfo.FromTime,
tempInfo.ToTime,
tempInfo.Tempearature);
}
For more information check this link on MSDN.
// Join "time" and "temperature"-tables,
// Get id, temperature, from time and to time
var query =
from time in ds.Tables["time"].AsEnumerable()
join temp in ds.Tables["temperature"].AsEnumerable()
on time.Field
temp.Field
select new
{
TemperatureId = time.Field<int>
Tempearature = temp.Field<string>
FromTime = time.Field
ToTime = time.Field<string>
};
// Simple output
foreach (var tempInfo in query)
{
Console.WriteLine("{0} - {1}:\t{2}",
tempInfo.FromTime,
tempInfo.ToTime,
tempInfo.Tempearature);
}
For more information check this link on MSDN.
