Situition: I am trying to fill a datagrid with data from
2 databases. I create 2 datasets and join them with a
datarelation. Then I run the project and an error
occurs 'This constraint cannot be enabled as not all
values have corresponding parent values'
The two tables in the dataset are 'Computer' and 'Users'
Users contain Unique ID's and acts as the PK while each
computer has a User and a user can have more than 1
computer.
I checked and all the computers have a user associated
with it. This is my first datarelation and am very new
with datasets. If anyone can give me some advice I would
appreciate it.
Thanks
Private Sub gridload()
Dim lconSQL As SqlConnection
lconSQL = gloGetSQLConnection("ComputerTracking")
Dim ds As New DataSet()
Dim strSQL As String
'Gather computer Information
Dim dcs1(0) As DataColumn
strSQL = "SELECT c_id, c_description, c_make,
c_model, c_users " _
& "FROM Computer"
Dim myda As New SqlDataAdapter(strSQL, lconSQL)
myda.Fill(ds, "Computer")
With ds.Tables("Computer")
dcs1(0) = .Columns("c_id")
.PrimaryKey = dcs1
End With
'Gather Usernames to build a data relation
strSQL = "SELECT UserID, Name FROM USERS"
lconSQL = gloGetSQLConnection("lsData")
myda = New SqlDataAdapter(strSQL, lconSQL)
myda.Fill(ds, "Users")
Dim dcs(0) As DataColumn
With ds.Tables("Users")
dcs(0) = .Columns("UserID")
.PrimaryKey = dcs
End With
'Build datareation
Dim drn As DataRelation
Dim dcParent As DataColumn
Dim dcChild As DataColumn
dcParent = ds.Tables("Computer").Columns
("c_users")
dcChild = ds.Tables("Users").Columns("UserID")
drn = New DataRelation("Info", dcParent, dcChild)
ds.Relations.Add(drn)
' ds.Relations.Add(drn)
DataGrid1.DataSource = drn
DataGrid1.DataBind()
End Sub So I need two connections.