troubleshooting Question


Avatar of mleopard
mleopard asked on
.NET Programming
4 Comments1 Solution731 ViewsLast Modified:
Can someone please help me with creating Data Relations in ASP.NET?  Here is my scenario.

I want to fill a dataset with 2 results using 2 dataAdapters.  And I keep getting an error on one line.  It makes no sense to me.  I have looked at examples till I am blue, now red in the face.  

The commented lines at the bottom are what is breaking and this is the error message.

Object reference not set to an instance of an object.

Anyway, ignore the datagrid because I was putting the data in the grid so I could see it.  However, If I run this code, I can only see the Customers info in the datagrid and not the Orders.  If I remove the "Customers"
in the following line:
daCustomers.Fill(DS, "Customers")
And remove "Orders"
daCustomers.Fill(DS, "Orders")
I can see all the data in the datagrid, but it looks really messed up.  Regardless, something is keeping me from creating the relation.  Any help is greatly appreciated.

Dim MyConnection As SqlConnection
Dim DS As DataSet
Dim daCustomers As SqlDataAdapter
Dim daOrders As SqlDataAdapter
Dim dr As DataRelation
Dim sqlCustomers As String = "select customerID, CompanyName from Customers"

Dim sqlOrders As String = "select OrderID, CustomerID, OrderDate, shippedDate from Orders"

DS = New DataSet()
MyConnection = New SqlConnection(connStr)

'Create first table
daCustomers = New SqlDataAdapter(sqlCustomers, MyConnection)
daCustomers.Fill(DS, "Customers")

'Create a second table
daOrders = New SqlDataAdapter(sqlOrders, MyConnection)
daOrders.Fill(DS, "Orders")

'Create Data Relation objects
Dim parentCol As DataColumn
Dim childCol As DataColumn

'Create relationship
'parentCol = DS.Tables("Customers").Columns("CustomerID")
'childCol = DS.Tables("Orders").Columns("CustomerID")

DataGrid1.DataSource = DS

These are the two lines that are breaking.  

'dr = New DataRelation("name", parentCol, childCol)


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros