显示两个表中的数据并消除重复

时间:2016-07-02 08:56:53

标签: mysql vb.net datagridview

下午好。在我提出问题之前,我想向您展示我的数据库和表格。

我在MySQL中有两个表

表1:purchorder

enter image description here

表2:接收

enter image description here

正如您在第一个表中看到的,表pucrhorder中的RINumbeR已在表receiving中更新。现在我的目标是做这样的事情。

enter image description here

在发布此问题之前,我尝试对其进行编码,但我的输出是这样的:

enter image description here

,代码是:

 Private Sub POHistory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim con1 As MySqlConnection = New MySqlConnection("server=localhost;userid=root;password=admin1950;database=inventory")
        Dim sql1 As MySqlCommand = New MySqlCommand("select purchorder.PONo,purchorder.ItemCode,purchorder.Description,purchorder.OrderQty,receiving.RINo,receiving.ItemCode,receiving.Description,receiving.ReceivedQty from purchorder,receiving where Purchorder.PONo = '" & TextBox1.Text & "' = receiving.RINo = '" & TextBox2.Text & "' GROUP BY Purchorder.ItemCode;", con1)
        Dim ds1 As DataSet = New DataSet
        Dim adapter1 As MySqlDataAdapter = New MySqlDataAdapter
        con1.Open()
        adapter1.SelectCommand = sql1
        adapter1.Fill(ds1, "MyTable")
        DataGridView1.DataSource = ds1.Tables(0)
        con1.Close()
    End Sub

怎么办?我是否需要在MYSQL中使用联接? Datagridview画?任何帮助表示赞赏。我想要的只是在上面的图像上显示数据(使用黄色标题)

TYSM

1 个答案:

答案 0 :(得分:0)

是的,如果您使用JOIN和GROUP BY,您将获得两个表的结果,并且您已分组的列没有重复