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
我想查看所有这些字段,但其中 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