hi i am using vb.net and winforms i have a datagrid which to it i am binding a dataset which has two relational datatables...
when i bind each datasets table individually to the datagrid they show... fine.. its in my relationship i am getting the error message which is highlighted below.. thanks in advance..sonia
global variables in forms module
Dim filepath As String allows user to get the path of the textfile to be retrieved
Dim oDT As New DataTable Datatable to hold the datasets table which is being passsed from another page
Dim oDSParentChild As New DataSet the dataset which is holding the two relational datatables
Dim oDSMeanReport As New DataSet this is holding the dataset of the data being retrieved from teh textfile
Dim oDSQuestion As New DataSet this is the dataset which is holding the dataset from another page
my form load is passing a Dataset from another form
this is a function to get data from a textfile and put in into a dataset
this procedure is creating a relationship between the two tables and it is adding them to the dataset
when i bind each datasets table individually to the datagrid they show... fine.. its in my relationship i am getting the error message which is highlighted below.. thanks in advance..sonia
global variables in forms module
Dim filepath As String allows user to get the path of the textfile to be retrieved
Dim oDT As New DataTable Datatable to hold the datasets table which is being passsed from another page
Dim oDSParentChild As New DataSet the dataset which is holding the two relational datatables
Dim oDSMeanReport As New DataSet this is holding the dataset of the data being retrieved from teh textfile
Dim oDSQuestion As New DataSet this is the dataset which is holding the dataset from another page
my form load is passing a Dataset from another form
Code:
Private Sub frmGetMean_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
oDSQuestion = varoDS
oDT = oDSQuestion.Tables(0)
oDT.TableName = "Questions"
End Sub
Code:
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuGetMeanFile.Click
OpenFileDialog1.Title = "Test"
OpenFileDialog1.InitialDirectory = "I:\StudentSurveyData\SPSS Main Report"
OpenFileDialog1.Filter = "txt files (*.txt)|*.txt"
OpenFileDialog1.FilterIndex = 2
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
filepath = OpenFileDialog1.FileName()
oDSMeanReport = delimitedDataSet(vbTab, filepath)
Me.DataGrid1.DataSource = ParentChildDataset
End If
End Sub
this is a function to get data from a textfile and put in into a dataset
Code:
Public Function delimitedDataSet(ByVal strdelimeter As String, ByVal strFilePath As String) As DataSet
Dim oDS As New DataSet
Dim oDT As New DataTable
Dim oDR As DataRow
Dim intcount As Int32
Dim strFields As String
Dim i As Int32
DATASET NAME, NAMESPACE, AND TABLE NAME
oDS.DataSetName = "test"
oDS.Namespace = "test"
oDS.Tables.Add("test")
Dim oSR As New StreamReader(strFilePath)
StreamReader()
GO TO THE TOP OF THE FILE AND GET THE BEGIN
oSR.BaseStream.Seek(0, SeekOrigin.Begin)
ADD THE HEADER COLUMNS TO THE DATSET
For Each strFields In oSR.ReadLine().Split(strdelimeter)
If strFields = "" Then
strFields = i
i = i + 1
End If
intcount = 0
oDS.Tables(0).Columns.Add(strFields)
Next
oSR.BaseStream.Seek(0, SeekOrigin.Current)
NOW ADD THE FIELDS
oDT = oDS.Tables(0)
While (oSR.Peek() > -1)
oDR = oDT.NewRow()
For Each strFields In oSR.ReadLine().Split(strdelimeter)
If strFields = "" Then
strFields = "Quest"
oDR(intcount) = strFields
intcount = intcount + 1
Else
If strFields <> "" Then
oDR(intcount) = strFields
intcount = intcount + 1
End If
End If
Next
intcount = 0
oDT.Rows.Add(oDR)
End While
Return oDS
End Function
this procedure is creating a relationship between the two tables and it is adding them to the dataset
Code:
Public Function ParentChildDataset() As DataSet
add a parent/child relationship between the two dataset
oDSParentChild.Relations.Add( _
"QuestionsAndMean", _
oDSParentChild.Tables("test").Columns("0"), _
oDSParentChild.Tables("Questions").Columns("QuestionId"))
[COLOR=Red]i get error here object is not set to an reference... can someone tell me why
i have all of my dataset and my datatables with a NEW keyword[/COLOR]
Return oDSParentChild
End Function