DavePro1962
Member
- Joined
- Feb 5, 2010
- Messages
- 6
- Programming Experience
- 1-3
Hi all
I am trying to bind 2 datagridviews together so that as I select a record in GDV 1 it populars the child records in DGV 2. I am using the following code that will not compile and I cant see why.
Thanks in advance
Dave
Imports System.IO
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Private m_da_Addresses As OleDbDataAdapter
Private m_da_TestScores As OleDbDataAdapter
Private m_DataSet As DataSet
' Save changes to the data.
Private Sub Form1_Closing(ByVal sender As Object, ByVal e _
As System.ComponentModel.CancelEventArgs) Handles _
MyBase.Closing
' Use a CommandBuilder to make the INSERT,
' UPDATE, and DELETE commands as needed.
Dim cb_addresses As New _
OleDbCommandBuilder(m_da_Addresses)
Dim cb_testscores As New _
OleDbCommandBuilder(m_da_TestScores)
' Update the database.
Try
m_da_Addresses.Update(m_DataSet, "Addresses")
m_da_TestScores.Update(m_DataSet, "TestScores")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Const SELECT_ADDRESSES As String = "SELECT * FROM " & _
"Addresses"
Const SELECT_TEST_SCORES As String = "SELECT * FROM " & _
"TestScores"
' Get the database file name.
Dim db_name As String = Application.StartupPath
db_name = db_name.Substring(0, db_name.LastIndexOf("\"))
db_name &= "\Contacts.mdb"
' Compose the connection string.
Dim connect_string As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_name & ";" & _
"Persist Security Info=False"
' Create a DataAdapter to load the Addresses table.
m_da_Addresses = New OleDbDataAdapter(SELECT_ADDRESSES, _
connect_string)
' Create a DataAdapter to load the Addresses table.
m_da_TestScores = New _
OleDbDataAdapter(SELECT_TEST_SCORES, connect_string)
' Create and fill the DataSet.
m_DataSet = New DataSet
m_da_Addresses.Fill(m_DataSet, "Addresses")
m_da_TestScores.Fill(m_DataSet, "TestScores")
' Define the relationship between the tables.
Dim data_relation As New _
DataRelation("Addresses_TestScores", _
m_DataSet.Tables("Addresses").Columns("ContactID"), _
_
m_DataSet.Tables("TestScores").Columns("ContactID"))
m_DataSet.Relations.Add(data_relation)
' Bind the DataGrids to the DataSet's tables.
'dgAddresses.DataSource= m_DataSet, "Addresses")
'dgTestScores.DataSource= m_DataSet, "Addresses.Addresses_TestScores")
dgAddresses.setDataBinding(m_DataSet, "Addresses")
dgTestScores.setDataBinding(m_DataSet, _
"Addresses.Addresses_TestScores")
End Sub
End Class
I am trying to bind 2 datagridviews together so that as I select a record in GDV 1 it populars the child records in DGV 2. I am using the following code that will not compile and I cant see why.
Thanks in advance
Dave
Imports System.IO
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Private m_da_Addresses As OleDbDataAdapter
Private m_da_TestScores As OleDbDataAdapter
Private m_DataSet As DataSet
' Save changes to the data.
Private Sub Form1_Closing(ByVal sender As Object, ByVal e _
As System.ComponentModel.CancelEventArgs) Handles _
MyBase.Closing
' Use a CommandBuilder to make the INSERT,
' UPDATE, and DELETE commands as needed.
Dim cb_addresses As New _
OleDbCommandBuilder(m_da_Addresses)
Dim cb_testscores As New _
OleDbCommandBuilder(m_da_TestScores)
' Update the database.
Try
m_da_Addresses.Update(m_DataSet, "Addresses")
m_da_TestScores.Update(m_DataSet, "TestScores")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
Const SELECT_ADDRESSES As String = "SELECT * FROM " & _
"Addresses"
Const SELECT_TEST_SCORES As String = "SELECT * FROM " & _
"TestScores"
' Get the database file name.
Dim db_name As String = Application.StartupPath
db_name = db_name.Substring(0, db_name.LastIndexOf("\"))
db_name &= "\Contacts.mdb"
' Compose the connection string.
Dim connect_string As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & db_name & ";" & _
"Persist Security Info=False"
' Create a DataAdapter to load the Addresses table.
m_da_Addresses = New OleDbDataAdapter(SELECT_ADDRESSES, _
connect_string)
' Create a DataAdapter to load the Addresses table.
m_da_TestScores = New _
OleDbDataAdapter(SELECT_TEST_SCORES, connect_string)
' Create and fill the DataSet.
m_DataSet = New DataSet
m_da_Addresses.Fill(m_DataSet, "Addresses")
m_da_TestScores.Fill(m_DataSet, "TestScores")
' Define the relationship between the tables.
Dim data_relation As New _
DataRelation("Addresses_TestScores", _
m_DataSet.Tables("Addresses").Columns("ContactID"), _
_
m_DataSet.Tables("TestScores").Columns("ContactID"))
m_DataSet.Relations.Add(data_relation)
' Bind the DataGrids to the DataSet's tables.
'dgAddresses.DataSource= m_DataSet, "Addresses")
'dgTestScores.DataSource= m_DataSet, "Addresses.Addresses_TestScores")
dgAddresses.setDataBinding(m_DataSet, "Addresses")
dgTestScores.setDataBinding(m_DataSet, _
"Addresses.Addresses_TestScores")
End Sub
End Class