anf
New member
- Joined
- Jan 12, 2006
- Messages
- 3
- Programming Experience
- Beginner
hi
what im trying to accomplish is to have the parent table in the combo box so that when the user selects an item the datagridview will fill with its child table's items. ex, if selecting someones name from the combo box, it would then display the persons info in the datagridview...
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Public objDataSetVendo As New DataSet
Dim dr As DataRelation
Friend WithEvents OleDbConnection As System.Data.OleDb.OleDbConnection
Friend WithEvents DaInfo As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents DaItems As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbSelectCommand2 As System.Data.OleDb.OleDbCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.OleDbConnection = New System.Data.OleDb.OleDbConnection
Me.OleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\Anf\My Documents\Visual Studio 2005\Projects\dbVendo.mdb;"
Me.DaInfo = New System.Data.OleDb.OleDbDataAdapter
Me.DaItems = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbSelectCommand2 = New System.Data.OleDb.OleDbCommand
'connection
'command 1
Me.OleDbSelectCommand1.CommandText = "SELECT VendoId, VendoName FROM tblMachines"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection
Me.DaInfo.SelectCommand = Me.OleDbSelectCommand1
'command 2
Me.OleDbSelectCommand2.CommandText = "SELECT ItemId, VendoId, ItemName FROM tblItems WHERE VendoId = VendoId"
Me.OleDbSelectCommand2.Connection = Me.OleDbConnection
Me.OleDbSelectCommand2.Parameters.Add(New OleDbParameter("VendoId", OleDbType.Numeric, 256, "tblMachines.VendoId"))
Me.DaItems.SelectCommand = Me.OleDbSelectCommand2
Try
Me.DaInfo.Fill(objDataSetVendo, "tblMachines")
Me.DaItems.Fill(objDataSetVendo, "tblItems")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
dr = New DataRelation("bla", objDataSetVendo.Tables("tblMachines").Columns("VendoId"), objDataSetVendo.Tables("tblItems").Columns("VendoId"))
objDataSetVendo.Relations.Add(dr)
Me.cboInfo.DataSource = Me.objDataSetVendo.Tables("tblMachines")
Me.cboInfo.DisplayMember = "VendoId"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub cboInfo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboInfo.Click
Try
objDataSetVendo.Clear()
Me.OleDbSelectCommand2.CommandText = "SELECT ItemId, VendoId, ItemName FROM tblItems WHERE VendoId = VendoId"
Me.OleDbSelectCommand2.Connection = Me.OleDbConnection
'Me.DaItems.SelectCommand.Parameters("VendoId").Value = cboInfo.Text
Me.DaInfo.Fill(objDataSetVendo, "tblMachines")
Me.DaItems.Fill(objDataSetVendo, "tblItems")
'Me.cboInfo.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
dgvItems.DataSource = objDataSetVendo.Tables("tblItems")
End Sub
what im trying to accomplish is to have the parent table in the combo box so that when the user selects an item the datagridview will fill with its child table's items. ex, if selecting someones name from the combo box, it would then display the persons info in the datagridview...
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Public objDataSetVendo As New DataSet
Dim dr As DataRelation
Friend WithEvents OleDbConnection As System.Data.OleDb.OleDbConnection
Friend WithEvents DaInfo As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents DaItems As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbSelectCommand2 As System.Data.OleDb.OleDbCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.OleDbConnection = New System.Data.OleDb.OleDbConnection
Me.OleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\Anf\My Documents\Visual Studio 2005\Projects\dbVendo.mdb;"
Me.DaInfo = New System.Data.OleDb.OleDbDataAdapter
Me.DaItems = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbSelectCommand2 = New System.Data.OleDb.OleDbCommand
'connection
'command 1
Me.OleDbSelectCommand1.CommandText = "SELECT VendoId, VendoName FROM tblMachines"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection
Me.DaInfo.SelectCommand = Me.OleDbSelectCommand1
'command 2
Me.OleDbSelectCommand2.CommandText = "SELECT ItemId, VendoId, ItemName FROM tblItems WHERE VendoId = VendoId"
Me.OleDbSelectCommand2.Connection = Me.OleDbConnection
Me.OleDbSelectCommand2.Parameters.Add(New OleDbParameter("VendoId", OleDbType.Numeric, 256, "tblMachines.VendoId"))
Me.DaItems.SelectCommand = Me.OleDbSelectCommand2
Try
Me.DaInfo.Fill(objDataSetVendo, "tblMachines")
Me.DaItems.Fill(objDataSetVendo, "tblItems")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
dr = New DataRelation("bla", objDataSetVendo.Tables("tblMachines").Columns("VendoId"), objDataSetVendo.Tables("tblItems").Columns("VendoId"))
objDataSetVendo.Relations.Add(dr)
Me.cboInfo.DataSource = Me.objDataSetVendo.Tables("tblMachines")
Me.cboInfo.DisplayMember = "VendoId"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub cboInfo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboInfo.Click
Try
objDataSetVendo.Clear()
Me.OleDbSelectCommand2.CommandText = "SELECT ItemId, VendoId, ItemName FROM tblItems WHERE VendoId = VendoId"
Me.OleDbSelectCommand2.Connection = Me.OleDbConnection
'Me.DaItems.SelectCommand.Parameters("VendoId").Value = cboInfo.Text
Me.DaInfo.Fill(objDataSetVendo, "tblMachines")
Me.DaItems.Fill(objDataSetVendo, "tblItems")
'Me.cboInfo.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
dgvItems.DataSource = objDataSetVendo.Tables("tblItems")
End Sub