我从上一页提取订单ID以从表格中选择特定订单,并且工作正常。我还需要从该表中获取CustomerID并查询customer表以返回具有该ID的条目。
@{
var id=Request["id"];
var SQLSELECT3 = "SELECT * FROM Ordr WHERE ID=@0";
var db = Database.Open("OMD");
var ordr = db.QuerySingle(SQLSELECT3,id);
var oCustomerID=ordr.CustomerID;
var oStatus=ordr.Status;
var oID=ordr.ID;
var oDate=ordr.Date;
var oService=ordr.Service;
var oNotes=ordr.Notes;
var SQLSELECT = "SELECT * FROM Customer WHERE ID = @oCustomerID";
var customer = db.QuerySingle(SQLSELECT,id);
var cLastName=customer.LastName;
var cFirstName=customer.FirstName;
var cAddress=customer.Address;
var cCity=customer.City;
var cState=customer.State;
var cZip=customer.Zip;
var cPhone1=customer.Phone1;
var cPhone2=customer.Phone2;
var cEmail=customer.Email;
}
答案 0 :(得分:1)
将您的查询更改为
var SQLSELECT = "SELECT * FROM Customer WHERE ID = @0";
var customer = db.QuerySingle(SQLSELECT, (int)ordr.CustomerID);
与您的问题无关,但我不明白为什么您将从查询中获得的所有值转移到另一组变量。在我看来,这是大量不必要的打字。