473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Datarelations

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.
Nov 18 '05 #1
0 883

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Les | last post by:
I have a problem getting Dataset.WriteXml() to create a nested xml realtionship. All I get is an inline xsd (all nodes are children of the root). Documentation says to use...
4
by: niv | last post by:
Hi, I am unsure on how to retrieve data from tables 2 tables that are related through a relationship table.. TableOne -------- TableOneID TableOneDesc
3
by: Kevin | last post by:
Hi All this is going to be a lengthy questions do please bear with me.... I have a database that has three tables - Employees, ShiftHeader,ShiftDetails Now the employees table holds the...
0
by: Randy | last post by:
I have two DataTables in a DataSet. I create a DataRelation between two like-typed columns in the first and second tables, and it works exactly as expected. Unfortunately, the default behavior...
1
by: Fleckman | last post by:
I have a DataSet with 14 DataTables and 18 Relationships that were defined within Visual Studio .NET 2003. Everything looks OK in the visual development environment, i.e. when I preview the DataSet...
2
by: Phil Townsend | last post by:
I have seen a lot on ADO.NET data relations, but my jury is still out on the benefits of coding a data relation vs. using a join in a stored procedure. I know there is more overhead when using the...
1
by: Lerp | last post by:
Hi all, I have a dataset made up of 3 tables that is bound to a datalist. On the itemdataBound event I call a sub that grabs a value (an id value) from the current row being outputted, queries...
0
by: George Durzi | last post by:
I have a DataSet with 3 tables, and two DataRelations dsSubs.Tables.TableName = "Subscriptions" dsSubs.Tables.TableName = "AccountManagers" dsSubs.Relations.Add "AccountManagers_Subscriptions",...
3
by: Carlos Albert | last post by:
Hello everybody, I'm using some gridviews with datalists inside template columns. Now, for each datalist I'm calling a method returning a dataset (depending from a column from the gridview). ...
0
by: Vajrala Narendra | last post by:
hi all, am working in asp.net i am using two data entry screens for parent and child tables. i heard that using datarelations we can achieve this using single screen. is it ppossible? please...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.