master/detail application?

KingSoh

New member
Joined
Jun 5, 2012
Messages
2
Programming Experience
3-5
Hi,
I need a help in solving this VB2005 Problem.I am trying to work with two tables, a student table and Subject Table as my datasource in Access. I want this to be master/detail application. I managed to code the detail(Subject) info in a datagridview at runtime as shown below. Now I need to link the Student info on the form to the datagridview so that when a studentNo is selected, I can add data from both the grid and the form to the database. Hope someone help me with this.
Thanks for your support.
Kingsoh


Public Class Form3
Dim objda As New OleDbDataAdapter
Dim SubjectsjnrTable As DataTable
Dim Bindingsource1 As BindingSource

Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'---add columns to the DataGridView control---
' DataGridView1.Columns.Add("Subject", "Subject ID")
' DataGridView1.Columns.Add("StudentNo", "Student No")
' DataGridView1.Columns.Add("Level", "Level")
'DataGridView1.Columns.Add("TeacherID", "TeacherID")
'---create a new bindingsource control---
Dim bindingsource As New BindingSource
'---add the items into the control---
bindingsource.Add("EnglishLanguage ")
bindingsource.Add("Maths")
bindingsource.Add("Sesotho")
bindingsource.Add("DVS")
bindingsource.Add("AgricScience")
bindingsource.Add("BusinessEducation")
bindingsource.Add("IT")
bindingsource.Add("PhysicalEducation")
bindingsource.Add("Religion")
bindingsource.Add("Science")
bindingsource.Add("PhysicalScience")
bindingsource.Add("Biology")
bindingsource.Add("Commerce")
bindingsource.Add("Accounting")

'....Create a new bidingsource control...
Dim bindingSource2 As New BindingSource
'....add the items into the controls....
bindingSource2.Add("A")
bindingSource2.Add("B")
bindingSource2.Add("C")
bindingSource2.Add("D")
bindingSource2.Add("E")

'---create a combobox column---
Dim comboBoxCol As New DataGridViewComboBoxColumn
'---set the header---
comboBoxCol.HeaderText = "SubjectID"

'---data bind it---
comboBoxCol.DataSource = bindingsource
'---add a combobox column to the DataGridView control---
DataGridView1.Columns.Add(comboBoxCol)
'....Ceate the second combobox column....
Dim combobox2col As New DataGridViewComboBoxColumn
'......set the header...
combobox2col.HeaderText = "Level"
'......bind with data....
combobox2col.DataSource = bindingSource2
'.... add a combobox column to the Datagridview control ....
DataGridView1.Columns.Add(combobox2col)

End Sub

Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub

Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Me.objda.Update(CType(Me.Bindingsource1.DataSource, DataTable))

End Sub
End Class
 
Back
Top