当我单击“打印”按钮时,我试图从两个表中检索数据以填充文本框ex,但我收到一条错误消息:
Column 'UID' in where clause is ambiguous.
我有两个名为 tableProducts 的表,其中包含 ProductID、ProductName 和 ProductPrice 列,以及包含 QuantityID 和 AvailableQuantity 列的 tableQuantity。
这是我的代码。
SqlClientConn.Open()
Dim SQLString As String = "SELECT ProductName,ProductPrice FROM tableProducts INNER JOIN tableQuantity ON tableProducts.ProductID = tableQuantity.QuantityID WHERE ProductID='" & txtid.Text & "'"
Dim mySqlDataAdapter As MySql.Data.MySqlClient.MySqlDataAdapter = New MySql.Data.MySqlClient.MySqlDataAdapter(SQLString, SqlClientConn)<br>
Dim ds As New DataSet
mySqlDataAdapter.Fill(ds)
If ds.Tables("tableProducts").Rows.Count > 0 Then
txtname.Text = ds.Tables(ProductName).Rows(0).Item(0).ToString()
txtprice.Text = ds.Tables(ProductPrice).Rows(0).Item(1).ToString()
txtquantity.Text = ds.Tables(AvailableQuantity).Rows(0).Item(2).ToString()
End If
SqlClientConn.Close()
最佳答案
ProductID 存在于 tableProducts 和 tableProducts 的两个表中,所以它说
where子句中的列不明确
SELECT ProductName,ProductPrice FROM tableProducts INNER JOIN tableQuantity ON tableProducts.ProductID = tableQuantity.QuantityID WHERE ProductID='" & txtid.Text & "'"
为表产品使用别名 试试这个查询
SELECT ProductName,ProductPrice FROM tableProducts INNER JOIN tableQuantity ON tableProducts.ProductID = tableQuantity.QuantityID WHERE tableProducts.ProductID='" & txtid.Text & "'"
或
SELECT a.ProductName,a.ProductPrice FROM tableProducts a INNER JOIN tableQuantity ON tableProducts.ProductID = tableQuantity.QuantityID WHERE a.ProductID='" & txtid.Text & "'"
希望对你有帮助
关于mysql - 从两个表中检索数据时如何填充文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29689830/