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:
And remove "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)
'Create a second table
daOrders = New SqlDataAdapter(sqlOrders, MyConnection)
'Create Data Relation objects
Dim parentCol As DataColumn
Dim childCol As DataColumn
'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)