Parent/Child Records Question

lorena

Well-known member
Joined
Oct 23, 2003
Messages
134
Location
Phoenix, Arizona
I am writing a windows application that interfaces with a SQL database. I want to set up a form that uses data from a parent table (RR_Record) and a child table (RR_Level) based on a value selected by a user from a combobox.

The form loads key values for the parent records with no problem.

When the user selects one of the choices in the ComboBox, the parent record should populate a series of textboxes on the form and the related child records will be a source for a DataGridView on the form.

I created a Data Tier/Data Access Level. Here is the code for that:
Code:
Public Class RecordAndLevelDataTier
  Class level variables for the DataSet and TableAdapters
  Private aDataSet As RecordAndLevelDataSet
  Private aRecordTableAdapter As RecordAndLevelDataSetTableAdapters.RiskReleaseRecordTableAdapter
  Private aLevelTableAdapter As RecordAndLevelDataSetTableAdapters.RiskReleaseLevelTableAdapter

  Public Function getRecordAndLevelData() As RecordAndLevelDataSet
    Instantiate the DataSet and TableAdapters
    aDataSet = New RecordAndLevelDataSet
    aRecordTableAdapter = New RecordAndLevelDataSetTableAdapters.RR_RecordTableAdapter
    aLevelTableAdapter = New RecordAndLevelDataSetTableAdapters.RR_LevleTableAdapter

    Fill both of the adapters
    aRecordTableAdapter.Fill(aDataSet.RR_Record)
    aLevelTableAdapter.Fill(aDataSet.RR_Level)
    Return the dataset
    Return aDataSet

  End Function

End Class

Here is the code from the windows form:
Code:
Form Level Variables
Dim aRiskReleaseData As New RecordAndLevelDataTier
Dim aDataSet As RecordAndLevelDataSet
Private aBindingSource As BindingSource

Private Sub RiskReleaseForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
    aDataSet = aRiskReleaseData.getRecordAndLevelData
    aBindingSource = New BindingSource
    With aBindingSource
      .DataSource = aDataSet
      .DataMember = "RiskReleaseRecord"
      .Sort = "RiskRelNo"
    End With
    With Me.rrNoComboBox
      .DataSource = aBindingSource
      .DisplayMember = "RiskRelNo"
      .ValueMember = "RiskRelNo"
      .DataBindings.Add("text", aBindingSource, "RiskRelNo", False, DataSourceUpdateMode.Never)
      .SelectedIndex = 0
    End With
End Sub

Here is the combobox code
Private Sub rrNoComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles rrNoComboBox.SelectedIndexChanged
    Dim rrNoString As String
    rrNoString = rrNoComboBox.SelectedValue.ToString

    Dim aDataSet As New DataSet

    Dim recordDataRow As DataRow
    recordDataRow = aDataSet.RiskReleaseRecord.FindByRiskRelNo(rrNoString)


    Dim levelDataRow() As DataRow
    levelDataRow = recordDataRow.GetChildRows("RecordToLevelRelation")
End Sub

At this point, I get "Value of type 1-dimensional array of System.Data.DataRow cannot be converted to System.Data.DataRow"

I know I am missing something huge. I guess I feel this is doable, I am just confused as to how to do it.
Thanks in advance for any help
 
I wound up fixing the problem. I did a rework on much of the code. Part of my problem was this line:
Code:
Dim levelDataRow() As DataRow

which should have been
Code:
Dim levelDataRow() As DataRow()

If anyone else has encountered a similiar issue, here is my solution.
Code:
Sub Load_Existing_Record()
    Dim rrNoString As String
    Dim recordDataRow As DataRow
    Dim levelDataRow As DataRow
    Dim levelDataRows As DataRow()

    Dim i As Integer

    Me.RiskReleaseRecordTableAdapter.Fill(Me.RecordAndLevelDataSet.RiskReleaseRecord)
    Me.RiskReleaseLevelTableAdapter.Fill(Me.RecordAndLevelDataSet.RiskReleaseLevel)


    Try
      rrNoString = rrNoComboBox.SelectedValue.ToString
      recordDataRow = Me.RecordAndLevelDataSet.RiskReleaseRecord.FindByRiskRelNo(rrNoString)
      levelDataRows = recordDataRow.GetChildRows("RecordToLevelRelation")
      
      Me.rrLevelDataGridView.DataSource = levelDataRows
      
    Catch ex As Exception
      MessageBox.Show("The Error is: " & ex.Message.ToString, "ERROR")
    End Try

  End Sub
 
Back
Top