Hi,
I am trying to learn how to create relations I got a sample from a web site and it works great, but when I tried to make one; it is not working. Can some one tell me what I am doing wrong. It gets down to the last relation that I made called "ProdDet" and jumps out of the whole method. The error message says the following:
System.ArgumentException: These columns don't currently have unique values.
at System.Data.ConstraintCollection.AddUniqueConstraint(UniqueConstraint constraint)
at System.Data.ConstraintCollection.Add(Constraint constraint, Boolean addUniqueWhenAddingForeign)
at System.Data.ConstraintCollection.Add(Constraint constraint, Boolean addUniqueWhenAddingForeign)
at System.Data.DataRelationCollection.DataSetRelationCollection.AddCore(DataRelation relation)
If I take out the last relation it works fine. And the SQl statement runs fine in SQL Server.
Any ideas I would appreciate.
Thank you
Here is my code:
Dim cnn As New SqlClient.SqlConnection(Util.SQLbConnect)
Dim DSNWind As DataSet
Dim DACustomers As New SqlClient.SqlDataAdapter("SELECT CustomerID, CompanyName, ContactName, Country FROM customers WHERE country = 'Germany'", cnn)
Dim DAOrders As New SqlClient.SqlDataAdapter("SELECT CustomerID, OrderID, OrderDate, ShippedDate, ShipVia, Freight FROM orders where customerid in (select customerid from customers where country = 'Germany')", cnn)
Dim DAOrderDetails As New SqlClient.SqlDataAdapter("Select * from [Order Details] where OrderID in (SELECT OrderID FROM orders where customerid in (select customerid from customers where country = 'Germany'))", cnn)
Dim DAProductDetails As New SqlClient.SqlDataAdapter("Select * from [Order Details],Products Where [Order Details].ProductID = Products.ProductID", cnn)
Try
DSNWind = New DataSet()
cnn.Open()
DACustomers.Fill(DSNWind, "dtCustomers")
DAOrders.Fill(DSNWind, "dtOrders")
DAOrderDetails.Fill(DSNWind, "dtOrderDetails")
DAProductDetails.Fill(DSNWind, "dtProductDetails")
'Close the connection to the data store; free up the resources
cnn.Close()
'Create a data relation object to facilitate the relationship
'between the Customers and Orders data tables.
DSNWind.Relations.Add("CustToOrd", DSNWind.Tables("dtCustomers").Columns("CustomerID"), DSNWind.Tables("dtOrders").Columns("CustomerID"))
DSNWind.Relations.Add("OrdToDet", DSNWind.Tables("dtOrders").Columns("OrderID"), DSNWind.Tables("dtOrderdetails").Columns("OrderID"))
DSNWind.Relations.Add("ProdDet", DSNWind.Tables("dtOrderdetails").Columns("ProductID"), DSNWind.Tables("dtProductDetails").Columns("ProductID"))