[英]How to retrieve data from more then two table of MS Access database using c#
我想從3個相互連接的表中從MS Access數據庫中檢索數據。
我在業務層寫了這段代碼
public List<ProductOrderModel> Show()
{
OleDbConnection cn;
try
{
ProductOrderModel dtoobj = new ProductOrderModel();
DataLayer dalobj = new DataLayer();
OleDbCommand cmdshow = new OleDbCommand();
cmdshow.CommandText = "select [CustomerVT].[Customer_Name],[OrderVT].[Order_Date],[ProductVT].[Price],[ProductVT].[Item_Name],[OrderVT].[Quantity],[OrderVT].[Order_ID] from [OrderVT] inner join [CustomerVT] on [OrderVT].[Customer_ID]=[CustomerVT].[Customer_ID] inner join [ProductVT] on [OrderVT].[Product_ID]=[ProductVT].[Product_ID] ";
List<ProductOrderModel> Ldemo = new List<ProductOrderModel>();
return dalobj.executereader(Ldemo, cmdshow, "BillingData");
}
catch (Exception ex2)
{
throw new DataException("error....." + ex2.Message);
}
}
和ExecuteReader()
代碼是..
public List<ProductOrderModel> executereader(List<ProductOrderModel> Ldemo, OleDbCommand cmdshow, string tablename)
{
OleDbConnection cn;
try
{
cn = this.getconnection();
cmdshow.Connection = cn;
cn.Open();
OleDbDataReader rd = cmdshow.ExecuteReader();
while (rd.Read())
{
ProductOrderModel dtoobj1 = new ProductOrderModel();
dtoobj1.InvoiceNo = Convert.ToInt32(rd["Order_ID"].ToString());
dtoobj1.CustomerName = rd["Customer_Name"].ToString();
dtoobj1.ItemName = rd["Item_Name"].ToString();
dtoobj1.Quantity = Convert.ToInt32(rd["Quantity"].ToString());
dtoobj1.Price = Convert.ToInt32(rd["Price"].ToString());
dtoobj1.OrderDate = Convert.ToDateTime(rd["Order_Date"].ToString());
Ldemo.Add(dtoobj1);
}
cn.Close();
return Ldemo;
}
catch (Exception ex2)
{
throw new DataException("error....." + ex2.Message);
}
}
但顯示錯誤
查詢表達式'[OrderVT]。[Customer_ID] = [CustomerVT]。[Customer_ID]內部聯接[OrderVT]上的[Customer_ID]內部聯接。[Product_ID] = [ProductVT]。[Product_ID]'的語法錯誤(缺少運算符)
請幫忙。 提前致謝。
使用如下括號
select [CustomerVT].[Customer_Name],[OrderVT].[Order_Date],[ProductVT].[Price],[ProductVT].[Item_Name],[OrderVT].[Quantity],[OrderVT].[Order_ID]
from ([OrderVT]
inner join [CustomerVT] on [OrderVT].[Customer_ID]=[CustomerVT].[Customer_ID])
inner join [ProductVT] on [OrderVT].[Product_ID]=[ProductVT].[Product_ID]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.