HOW TO JOIN TWO TABLES IN DATAGRIDVIEW

  • Thread starter Thread starter Omi4u
  • Start date Start date
O

Omi4u

Guest
Dear All

I have two tables

stockin and stockinjoin

both have relation using stockinid

now i wrote below codes to display both data in one datagridview

Public Sub Getdata()
Try
Dim constring As String = appx.myconnection
Using con As New SqlConnection(constring)
Using cmd As New SqlCommand("SELECT s.stockinid,s.stockindate,s.gatepassid,s.purchaseordernumber,s.supplierid,s.suppliername,s.suppliercontact,s.supplieraddress,s.supplieremail,s.username,s.approvedby,s.approved,s.totalamount,s.totalitems,d.itemid,d.itemname,d.description,d.stockinhand,d.newqty,d.unit,d.previousamount,d.newprice,d.totalprice FROM stockinitems s JOIN stockinjoin d ON s.stockinid=d.stockinid", con)
cmd.CommandType = CommandType.Text
Using sda As New SqlDataAdapter(cmd)
Using dt As New DataTable()
sda.Fill(dt)
StockinitemsDataGridView.AutoGenerateColumns = False



StockinitemsDataGridView.DataSource = dt

End Using
End Using
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub

now above code is only showing me data from stockin table but not from other .

also it showing me repeat data as in attachment picture

1605666.jpg

Continue reading...
 
Back
Top