DataRelation

  • Thread starter Kevin Davis via DotNetMonster.com
  • Start date
K

Kevin Davis via DotNetMonster.com

Aloha,

I have a question when using the Datarelation. I built a dataset and need
to use the Datarelation to build parent-child relationships. I have events
that may or may not use resources. I have a resources table which has the
resourceID, eventID, and amount. My code blows up because "The Constraint
cannot be enabled as not all values have corresponding parent values." I
double checked to ensure I did not have any orphan values in the child
table.

My questions is: Can I use the datarelation if my event does not have a
resource (meaning that there will not be a corresponding child record in
the resource table.)

Any help is appreciated.

Mahalo!

Kevin Davis
 
G

Guillaume Davion

By the way, you can use this code snippet to see exactly where the
error does come from.

try
'Fill your datatable
Catch e As Data.ConstraintException
'Creation of a log file
Dim strWriter As StreamWriter = _
File.CreateText("c:\ExtractErr.log")
strWriter.WriteLine("Table ACTIVITE")

'ACTIVITES is the typed datatable i'm trying to fill
Dim v_errorRows As DataRow() = .ACTIVITES.GetErrors
For Each v_row As DataRow In v_errorRows
strWriter.WriteLine(v_row.RowError)
Next

strWriter.Flush()
strWriter.Close()

return()
End Try

Good luck
 
K

Kevin Davis via DotNetMonster.com

Here is an example of my code:
Dim eventstring as DBCommandWrapper = db.GetSqlStringCommandWrapper("EVENT
SELECT Statement")
Dim resourcestring as DBCommandWrapper = db.GetSqlStringCommandWrapper
("RESOURCE SELECT Statement")
db.LoadDataSet(eventstring, eventsdataset, "Events")
db.LoadDataset(resourcestring, eventdataset, "Resources")

******
Here is where my code blows up
******

dim eventrelationship as DataRelation = eventsdataset.Relations.Add
("EvtResources", eventsdataset.Tables("Events").Columns("EventID"),
eventsdataset.Tables("Resources").Columns("EventsID"))

My question is where can I set the dataconstraint value to false?

Your suggestion makes perfect sense and I believe should work, but where
can I set that?

Aloha,

Kev
 
J

Jason Bentley

Kevin, you will have to use the Public Sub New(String, DataColumn,
DataColumn, Boolean) of the DataRelation, not the one you are currently
using. Obviously, the boolean value is false for the createConstraints
property.

Jason Bentley
http://geekswithblogs.net/jbentley
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top