Linq To DataSet

时间:2022-09-02 22:13:16
        private static void LinqToDataSet()
{
string sql = "select * from Advertising";
using (DataSet ds = GetDataSet(sql))
{
if (ds != null)
{
if (ds.Tables[].Rows.Count > )
{
//查询全局广告
List<Advertising> listCompany = new List<Advertising>();
Guid guid = new Guid("B362A0D1-99D2-432F-8345-28D0E0B94B88");
//查询总部和广告
var Company = from adv in ds.Tables[].AsEnumerable()
where adv.Field<int>("AdvertisingType").ToString() != "" && adv.Field<Guid>("CompanyId") == guid
orderby adv.Field<int>("AdvertisingType") ascending, adv.Field<int>("Orders") ascending
select new
{
AdvertisingId = adv.Field<Guid>("AdvertisingId"),
AdvertisingName = adv.Field<string>("AdvertisingName"),
SupplierId = adv.Field<Guid>("SupplierId"),
CompanyId = adv.Field<Guid>("CompanyId"),
AdvertisingType = adv.Field<int>("AdvertisingType"),
StartTime = adv.Field<DateTime>("StartTime"),
EndTime = adv.Field<DateTime>("EndTime"),
Orders = adv.Field<int>("Orders"),
Content = adv.Field<string>("Content"),
AdvertisingArea = adv.Field<int>("AdvertisingArea"),
FilePath = adv.Field<string>("FilePath")
}; foreach (var company in Company)
{ Advertising advertising = new Advertising();
advertising.AdvertisingId = company.AdvertisingId.ToString();
advertising.AdvertisingName = company.AdvertisingName;
advertising.SupplierIdId = company.SupplierId.ToString();
advertising.CompanyId = company.CompanyId.ToString();
advertising.AdvertisingType = company.AdvertisingType;
advertising.StartTime = company.StartTime;
advertising.EndTime = company.EndTime;
advertising.Orders = company.Orders;
advertising.Content = company.Content;
advertising.AdvertisingArea = company.AdvertisingArea;
advertising.FilePath = company.FilePath; listCompany.Add(advertising);
}
File.WriteAllText("c:/System.txt", ToJson(listSystem)); Console.WriteLine("生成完成");
// DataRow[] drCountry = ds.Tables[0].Select(where);
}
}
}
}