Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

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:

'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

Posted

I wound up fixing the problem. I did a rework on much of the code. Part of my problem was this line:

Dim levelDataRow() As DataRow

 

which should have been

Dim levelDataRow() As DataRow()

 

If anyone else has encountered a similiar issue, here is my solution.

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...