0

我正在尝试根据用户输入的值从两个独立但相关的表(它们之间有一个外键)中获取数据。例如如果输入值textBox11,我的SQL语句是:

SQLCommandText = "select Invoice_Name.Inv_Nu, Invoice_Name.Price, Invoice_Name.IDate, AddInfo.Case_Nu, AddInfo.PaperName, AddInfo.Page_Nu, AddInfo.Case_Type, AddInfo.Size from Invoice_Name full outer join AddInfo on Invoice_Name.L_Name = " + "'" + textBox11.Text + "'";

这似乎无法正常工作,我似乎无法找出原因。

我有两张桌子是:

Invoice_Name
------------
Inv_Nu
L_Name
Price
IDate

AddInfo
-------
Inv_Nu
Case_Nu
PaperName
PageNumber
Case_Type
Size

我希望用户输入L_Name和程序来带回 L_Name 等于该值的两个表中的所有信息。这里的外键是取自 Invoice_Name 表的 Inv_Nu。

测试数据:

Invoice_Name: 
Inv_Nu | L_Name | Price | IDate
01064 | Rami Isleem | 215 | 19/6/2013

AddInfo:
Inv_Nu | Case_Nu | PaperName | Page_Nu | Case_Type | Size
01064 | 100/20 | Alra'i | 21 | abc | 2x8
4

1 回答 1

2

您必须加入 2 个表Inv_NU并过滤Invoice_Name.L_Name = textBox11.Text

"select Invoice_Name.Inv_Nu, Invoice_Name.Price, Invoice_Name.IDate, 
        AddInfo.Case_Nu, AddInfo.PaperName, AddInfo.Page_Nu, 
        AddInfo.Case_Type, AddInfo.Size 
   from Invoice_Name 
   left join AddInfo on Invoice_Name.Inv_NU = AddInfo.Inv_NU
  where Invoice_Name.L_Name = " + "'" + textBox11.Text + "'";

而不是FULL OUTER JOIN,使用 aLEFT JOIN因为您要过滤Invoice_Name行然后加入AddInfo行。

于 2013-06-24T12:30:04.967 回答