السلام عليكم يا اهل الاسلام
بحث كثيرا عن كود لتعبئة datagridview من جدولين بينهما علاقة لكن للاسف كل الاكواد لم تشتغل معي
وهذا آخر ما جربت وجدته في موقع اجنبي
' Dim SQLstr As String = " select * from TabCondidats inner join tabFacture on TabCondidats.NumContrat =tabFacture.Num_contrat"
'Open the Connetion
Con.Open()
'Dataset that holds data in disconnected mode
Dim ds As New DataSet
'Two commands for two tables (tab1 and tab2)
Dim cmd1 As OleDbCommand
Dim cmd2 As OleDbCommand
'Two datapaters to fill the dataset from two tables
Dim adp1 As OleDbDataAdapter
Dim adp2 As OleDbDataAdapter
'This handles the relationship between the two columns
Dim datarelation As DataRelation
Dim dc1 As DataColumn
Dim dc2 As DataColumn
'It's not important but gives your code more better way to
'compare strings between tables
ds.CaseSensitive = True
'First command for first table
cmd1 = New OleDbCommand
cmd1.Connection = Con
cmd1.CommandText = "SELECT NumContrat ,Nom FROM TabCondidats"
'Second command for Second table
cmd2 = New OleDbCommand
cmd2.Connection = Con
cmd2.CommandText = "SELECT * FROM TabFacture"
'Now , we will fill the first table and add it to the dataset
adp1 = New OleDbDataAdapter
adp1.SelectCommand = cmd1
adp1.TableMappings.Add("Table", "TabCondidats")
adp1.Fill(ds)
'As we did in the previous step , here for the Second table
adp2 = New OleDbDataAdapter
adp2.SelectCommand = cmd2
adp2.TableMappings.Add("Table", "TabFacture")
adp2.Fill(ds)
dc1 = ds.Tables("TabCondidats").Columns("NumCondidat")
dc2 = ds.Tables("TabFacture").Columns("Num_Condidat")
'Here we combined two datacolumns to the relations obj
datarelation = New DataRelation("TabCondidats and TabFacture", dc1, dc2)
ds.Relations.Add(datarelation)
'Simple one , bind the dataset after all operation to the
'Datagrid
GridSuivie_Consomation.DataSource = ds.DefaultViewManager
'Show the first table in the grid because it's the primary table
GridSuivie_Consomation.DataMember = "TabCondidats"افيدونا زادكم الله علما