populating datagridview2 with Version Table(Sqlexpress2008)

hassanintern

New member
Joined
Jun 4, 2013
Messages
4
Programming Experience
Beginner
Hi,
I am new to sql database so dont know much about it. I have 2 tables in database: Document table(docID;DocDescription are 2 columns) and Version table(docID; VersionName).
one document can have multiple versions of it.
so one docID can have multiple rows in Version table with same docID.

i want to populate dgv2 with a row-click-event of dgv1 which is already populated with DocumentTable. I only want to populate corresponding versions to that docID and i know i need to use WHERE clause but i dont know how to put in code: if someone can write one line, it will be great and explain it.
the code to populate:

Public Sub loadingVersions()

Dim adapter As New SqlDataAdapter()
Dim ds As New DataSet()


Dim con As New SqlConnection("Data Source=it7\SQLEXPRESS2012;Initial Catalog=DocumentManager;Integrated Security=True")
Dim cmd As SqlCommand = con.CreateCommand()

cmd.CommandText = "SELECT VersionName FROM Version WHERE docID = ??????????????"

adapter.SelectCommand = cmd
con.Open()
adapter.Fill(ds, "Version")
con.Close()
DataGridView2.DataSource = ds
DataGridView2.DataMember = "Version"
End Sub
 
Unless the amount of data is very large, I would suggest retrieving all data from both tables at the start and binding it to your two grids. If you bind it correctly then the child data will be filtered automatically. Here's how to bind it correctly:

Master/Detail (Parent/Child) Data-binding
 
Back
Top