如何从两个表中检索数据时填充文本框? [英] How to fill textboxes when the data are retrieving from two tables?

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

问题描述

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

..

推荐答案

你有两个表名为

tableProducts with Columns ProductI D,ProductName和ProductPrice AND tableQuantity,列为QuantityID和AvailableQuantity。请帮帮我。



问题编号。 1您正在从tableProducts中选择两列,然后选择运行连接查询或查询不完整的原因。


确定

以下是结构查询请尝试





You have two tables named
tableProducts with Columns ProductID, ProductName, and ProductPrice AND tableQuantity with columns QuantityID and AvailableQuantity. Please help me.

Question No . 1 You are selecting both columns from tableProducts then why you are running join query or your query incomplete .

Ok
following is the structure of query Please try


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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆