Im using two dataadapters to bring in 2 tables into a dataset and then creating a one to many relationship but I keep on getting this error
"Object Reference not set to an instance of the object"
Heres the code
can someone help
"Object Reference not set to an instance of the object"
Heres the code
can someone help
Code:
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\Access Database\SimpleDataAccessExample.mdb;"
Connection object
Dim mdbConn As OleDbConnection = New OleDbConnection(strConn)
DataAdapter for the customer table
Dim daCustomer As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Customer", mdbConn) where City=" & txtSearch.Text, mdbConn)
DataAdapter for the orders table
Dim daOrders As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Orders", mdbConn)
----------------------------------------------------------
opening and closing
mdbConn.Open()
Create DataSet
Dim dsCustomerOrder As New DataSet()
Fill DataSet
daCustomer.Fill(dsCustomerOrder)
daOrders.Fill(dsCustomerOrder)
Close the connection
mdbConn.Close()
----------------------------------------------------------
The tables are now loaded into the dataset and the
relationship between the Customer and Orders table can be added
Dim CustOrderRel As DataRelation = dsCustomerOrder.Relations.Add("CustOrder", _
dsCustomerOrder.Tables("Customer").Columns("CustomerID"), _
dsCustomerOrder.Tables("Orders").Columns("CustomerID"))
Dim pRow, cRow As DataRow
For Each pRow In dsCustomerOrder.Tables("Customer").Rows
Console.WriteLine(pRow("CustomerID").ToString())
Next
For Each cRow In pRow.GetChildRows(CustOrderRel)
Console.WriteLine(vbTab & cRow("OrderId").ToString())
Next
Catch ex As Exception
MsgBox(ex.Message & " ErrorSource: " & ex.Source & " Stacktrace: " & ex.StackTrace)
End Try