我使用以下代码来提取两个数据集,一个来自标题表,另一个来自详细信息表。
String connectionString = "user id=####; password=####!; server=####; database=####";
DataContext db = new DataContext
(connectionString);
Table<orderHeader> OrderHeader = db.GetTable<orderHeader>();
Table<orderDetails> OrderDetails = db.GetTable<orderDetails>();
List<clsOrders> orderexport = new List<clsOrders>();
List<clsOrdersDetails> orderDetailexport = new List<clsOrdersDetails>();
string custNumber;
string custOrderNumber;
IQueryable<orderHeader> ordqry =
from ord in OrderHeader
where ord.ORDERSTATUS == 1 || ord.ORDERSTATUS == 3
select ord;
foreach (var det in ordqry)
{
custNumber = det.CUSTNUM.ToString();
custOrderNumber = det.ORDERNUMBER;
IQueryable<orderDetails> orddetqry =
from orddet in OrderDetails
where orddet.ORDERNUMBER == custOrderNumber
select orddet;
foreach (var I in orddetqry)
{
clsOrdersDetails ordd = new clsOrdersDetails();
ordd.itemNum = I.ITEMNUM;
ordd.itemQty = I.ITEMQTY;
orderDetailexport.Add(ordd);
}
}
}
[Table(Name = "orderDetailsSurface")]
public class orderDetails
{
private int _ItemSeq;
[Column(IsPrimaryKey = true, Storage = "_ItemSeq")]
public int ITEMSEQ
{
get
{
return this._ItemSeq;
}
set
{
this._ItemSeq = value;
}
}
private string _ItemNum;
[Column(Storage = "_ItemNum")]
public string ITEMNUM
{
get
{
return this._ItemNum;
}
set
{
this._ItemNum = value;
}
}
private string _ItemQty;
[Column(Storage = "_ItemQty")]
public string ITEMQTY
{
get
{
return this._ItemQty;
}
set
{
this._ItemQty = value;
}
}
private int _ItemDesc;
[Column(Storage = "_ItemDesc")]
public int ITEMDESC
{
get
{
return this._ItemDesc;
}
set
{
this._ItemDesc = value;
}
}
private string _ItemCost;
[Column(Storage = "_ItemCost")]
public string ITEMCOST
{
get
{
return this._ItemCost;
}
set
{
this._ItemCost = value;
}
}
private string _ItemStatus;
[Column(Storage = "_ItemStatus")]
public string ITEMSTATUS
{
get
{
return this._ItemStatus;
}
set
{
this._ItemStatus = value;
}
}
private string _OrderNumber;
[Column(Storage = "_OrderNumber")]
public string ORDERNUMBER
{
get
{
return this._OrderNumber;
}
set
{
this._OrderNumber = value;
}
}
}
我收到“foreach(var in in ordedetqry)”中的错误,我检查了我的数据库设置和我的列,以确保我传递的是正确的变量类型。
我不确定什么是不正确的。
编辑:添加了orderDetails类
答案 0 :(得分:0)
我发现了这个问题,不知道为什么我之前没有看到它。我在orderDetails类中的一个公共变量被设置为INT,它应该是一个STRING。