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

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

本文介绍了如何从两个表中检索数据时填充文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to retrieve data from two tables to fill the textboxex when I'm click the Button Print but I got an error saying: Column 'UID' in where clause is ambiguous. I have two tables named tableProducts with Columns ProductID, ProductName, and ProductPrice AND tableQuantity with columns QuantityID and AvailableQuantity. Please help me.

Here are my codes.

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)
        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()

..

推荐答案

SELECT P.ProductName
,P.ProductPrice
FROM tableProducts  P
INNER JOIN tableQuantity Q ON (P.ProductID = Q.QuantityID)
WHERE P.ProductID=  txtid.Text 


这篇关于如何从两个表中检索数据时填充文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 20:07