mysql - 从两个表中检索数据时如何填充文本框?

标签 mysql vb.net

当我单击“打印”按钮时,我试图从两个表中检索数据以填充文本框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(&quot;tableProducts&quot;).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/

相关文章:

mysql - 在 where 子句中获取字符串值 - MySQL

mysql - 运行MYSQL代码时出错-- super 困惑

php - 使用php使用更多关键字搜索mysql数据库

javascript - 从类库调用 Javascript

mysql - 使用 MySQL 查询检索单个字符串的前两部分

vb.net - 获取文件资源管理器使用其窗口句柄显示的路径

asp.net-mvc - 在 MVC 中删除 DropDownList 上的空白条目

VB.NET Lambda 表达式

vb.net - 如何在VB.NET中使用DataGridView对数据进行排序?

mysql - 子查询返回超过 1 - 将值传递到子查询的问题