简体   繁体   English

我的SQL代码有什么问题?

[英]What's Wrong With My SQL Code?

I get this error 我得到这个错误

The specified field 'StockID' could refer to more than one table listed in the FROM clause of your SQL statement. 指定的字段“ StockID”可以引用SQL语句的FROM子句中列出的多个表。

Code: 码:

 cmd = New OleDbCommand("SELECT StockID as [Stock ID], ea.Products as [Product]," & _
                         "emp.Amount FROM Stock ea inner join tblProductDetails" & _
                         "emp on emp.StockID = ea.StockID", con)

I've set the relationship to tblProductDetails 's stockID to Stock 我已将与tblProductDetailsstockID的关系设置为Stock

Sorry for any obvious mistake. 抱歉,有任何明显的错误。

It means that the specified field 'StockID' could refer to more than one table listed in the FROM clause of your SQL statement. 这意味着指定的字段“ StockID”可以引用SQL语句的FROM子句中列出的多个表。

In other words, both Stock and tblProductDetails have a field named StockID , and it isn't sure which one you mean. 换句话说, StocktblProductDetails都有一个名为StockID的字段,并且不确定您指的是哪个字段。

You have to qualify it with the table name, eg SELECT ea.StockID or SELECT emp.StockID . 您必须使用表名来限定它,例如SELECT ea.StockIDSELECT emp.StockID

Even though you're joining and they both have the same value, you still have to specify one. 即使您要加入并且它们都具有相同的值,您仍然必须指定一个。 In your case, with an inner join, the choice is fairly arbitrary. 在您的情况下,使用内部联接,选择是相当任意的。

both your tables (Stock and tblProductDetails) has a field called [Stock ID]. 您的两个表(Stock和tblProductDetails)都有一个名为[Stock ID]的字段。 you will need to specify which one to use (either emp or ea) 您将需要指定使用哪个(emp或ea)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM