繁体   English   中英

VB.net Mysql连接3个表

[英]VB.net Mysql Joining 3 tables

我想查看所有这些字段,但是其中3个来自不同的表。

Dim sql As MySqlCommand = New MySqlCommand("SELECT tblproduct.ProductNo, tblgenericname.genericname, tblproduct.BrandName, tblproduct.Quantity, tblproduct.PurchasedDate, tblproduct.ExpirationDate from tblproduct, tblGenericName where tblproduct.Genericno = tblgenericname.genericno, tblcompany where tblproduct.CompanyNo = tblcompany.CompanyNo and tblcompany.CompanyName like '" & cmb_com_load.Text & "'order by BrandName", con)
    Dim da As MySqlDataAdapter = New MySqlDataAdapter()
    Dim ds As DataSet = New DataSet

    da.SelectCommand = sql
    da.Fill(ds, "rec")
    DataGridView1.DataSource = ds
    DataGridView1.DataMember = "rec"

您的SQL:

SELECT tblproduct.ProductNo, tblgenericname.genericname, tblproduct.BrandName, 
tblproduct.Quantity, tblproduct.PurchasedDate, tblproduct.ExpirationDate 
from tblproduct
join tblGenericName on tblproduct.Genericno = tblgenericname.genericno
join tblcompany on tblproduct.CompanyNo = tblcompany.CompanyNo 
where tblcompany.CompanyName like '" & cmb_com_load.Text & "'order by BrandName

暂无
暂无

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

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