D
dbuchanan
Hello,
Here is the error message;
----------------------------
Exception Message:
ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child
key values (5) to exist in the parent table.
----------------------------
I am encountering this error when I try to insert records into table
'tbl040Cmpt' using the DataSet1.Tables("Table").Rows.Add(row)
The relevant data structure goes like this the table 'tbl040Cmpt'
contains a field that stores the value from lookup table
'lkp302SensorType'.
Here is the relationship that exists in the Dataset;
\\
Me.Relations.Add("Lkp_tbl040Cmpt_lkp302SensorType",
Me.Tables("lkp302SensorType").Columns("pkSensorTypeId"),
Me.Tables("tbl040Cmpt").Columns("cmSmallint06"))
//
Here is the 'lkp302SensorType' lookup table;
\\
CREATE TABLE [lkp302SensorType] (
[pkSensorTypeId] [smallint] IDENTITY (1, 1) NOT NULL ,
[SensorType] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[Ord] [tinyint] NOT NULL CONSTRAINT [DF_lkp302SensorType_Ord] DEFAULT
(0),
[Hide] [bit] NOT NULL CONSTRAINT [DF_lkp302SensorType_Hide] DEFAULT
(0),
CONSTRAINT [PK_lkp302SensorType] PRIMARY KEY CLUSTERED
(
[pkSensorTypeId]
) WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY]
GO
//
Here are table 'tbl040Cmpt'
\\
CREATE TABLE [tbl040Cmpt] (
[pkComponentId] [char] (36) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL CONSTRAINT [DF_tbl040Cmpt_pkComponentId] DEFAULT (newid()),
[fkDevice] [char] (36) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[fkComponentType] [int] NOT NULL ,
[ComponentDescription] [varchar] (100) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[QuanSharingConfiguration] [tinyint] NOT NULL ,
[QuanConfigured] [tinyint] NOT NULL CONSTRAINT
[DF_tbl040Cmpt_QuanConfigured] DEFAULT (0),
[QuanActuations] [tinyint] NOT NULL CONSTRAINT
[DF_tbl040Cmpt_QuanActuations] DEFAULT (1),
[cmVarchar01] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar02] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar03] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar04] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar05] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar06] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmNumeric01] [numeric](5, 3) NULL ,
[cmNumeric02] [numeric](5, 3) NULL ,
[cmNumeric03] [numeric](5, 3) NULL ,
[cmNumeric04] [numeric](5, 3) NULL ,
[cmNumeric05] [numeric](5, 3) NULL ,
[cmNumeric06] [numeric](5, 3) NULL ,
[cmNumeric07] [numeric](5, 3) NULL ,
[cmBit01] [bit] NULL ,
[cmBit02] [bit] NULL ,
[cmBit03] [bit] NULL ,
[cmBit04] [bit] NULL ,
[cmBit05] [bit] NULL ,
[cmBit06] [bit] NULL ,
[cmBit07] [bit] NULL ,
[cmBit08] [bit] NULL ,
[cmBit09] [bit] NULL ,
[cmBit10] [bit] NULL ,
[cmBit11] [bit] NULL ,
[cmSmallint01] [smallint] NULL ,
[cmSmallint02] [smallint] NULL ,
[cmSmallint03] [smallint] NULL ,
[cmSmallint04] [smallint] NULL ,
[cmSmallint05] [smallint] NULL ,
[cmSmallint06] [smallint] NULL ,
[cmSmallint07] [smallint] NULL ,
[cmSmallint08] [smallint] NULL ,
[cmTinyint01] [tinyint] NULL ,
[SooOrder] [numeric](5, 3) NULL ,
[SooPrecedent] [numeric](5, 3) NULL ,
[SooDelay] [numeric](5, 3) NULL ,
[SooNote] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[cmUserNote] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[cmCreatedOn] [smalldatetime] NOT NULL ,
[cmCreatedBy] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[cmEditedOn] [smalldatetime] NOT NULL ,
[cmEditedBy] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[cmrowversion] [timestamp] NOT NULL ,
CONSTRAINT [PK_tbl040Cmpt] PRIMARY KEY CLUSTERED
(
[pkComponentId]
) WITH FILLFACTOR = 90 ON [PRIMARY] ,
CONSTRAINT [FK_tbl040Cmpt_lkp202ComponentType] FOREIGN KEY
(
[fkComponentType]
) REFERENCES [lkp202ComponentType] (
[pkComponentTypeId]
),
CONSTRAINT [FK_tbl040Cmpt_tbl030Devi] FOREIGN KEY
(
[fkDevice]
) REFERENCES [tbl030Devi] (
[pkDeviceId]
) ON DELETE CASCADE NOT FOR REPLICATION
) ON [PRIMARY]
GO
//
Here is selected code that causes the error'
\\
Private Sub InsertCylnSensor(ByVal s As String)
'Create a data row (collection of fields)
Dim row As DataRow = _dataSet1.Tables(_currentTable).NewRow
'MessageBox.Show("Insert is called for: " & s)
Try
' Data entered automatically
row("pkComponentId") = Guid.NewGuid.ToString
'row("fkDevice") = _pkDeviceIdForFkAndParameter
row("fkDevice") = f030Devi._pkDeviceIdForFkAndParameter
row("fkComponentType") = 7 'Motion sensor
' ClipDriver -
Clip Driver_1 Sensor_1 _ A(??)
row("ComponentDescription") = _
Me.txtComponentDescription.Text.ToString & _
" - " & _componentTypeNameForTitleAndCmptDescrip & "_" & s
row("QuanSharingConfiguration") = 1
row("QuanConfigured") = "0" 'This will be populated
OnSave after user enters data
'TODO - f041Cyln - InsertCylnSensor - QuanActuations -
'Propagate this on to the sensors ~ is this really necessary
row("QuanActuations") = _quanOfComponentActuations
'Propagate this on to the sensors
'TODO - f041Cyln - InsertCylnSensor - row("cmVarchar04") =
"On"
row("cmVarchar04") = "On"
row("cmVarchar06") = _pkCmptIdOfParentForSensorAndParameter
'Give all other positions a FALSE value and only the proper
position a TRUE value
' This allows proper filtering
row("cmBit01") = False 'B
row("cmBit02") = False 'D
row("cmBit04") = False 'C
row("cmBit05") = False 'A
Select Case s
Case "B"
row("cmBit01") = True 'B
Case "D"
row("cmBit02") = True 'D
Case "C"
row("cmBit04") = True 'C
Case "A"
row("cmBit05") = True 'A
End Select
row("cmBit06") = True 'PNP NON
row("cmBit07") = True 'is Motion sensor
row("cmSmallint01") = 1
'Me.cboSensorVoltage.NSelectedValue ~ (1 = 24 volt)
'cmSmallint02
'cmSmallint03
'cmSmallint04
'cmSmallint05
row("cmSmallint06") = 5 'Me.cboSensorType.NSelectedValue
~ (5 = Hall effect)
'cmSmallint07
row("cmSmallint08") = 2
'Me.cboSensorConnection.NSelectedValue ~ (2 = Micro)
row("cmUserNote") = ""
row("cmCreatedOn") = Now.ToString
row("cmCreatedBy") = SystemInformation.UserName.ToString
row("cmEditedOn") = Now.ToString
row("cmEditedBy") = SystemInformation.UserName.ToString
' The following data is entered by the user - later
'row("cmVarchar01") = ucase(Me.txtSensorIOAddress.Text)
' The following data is confirmed by the user - later
'row("cmBit06") = True 'PNP NON
Catch ane As ArgumentNullException
'The exception that is thrown when a null reference
(Nothing in Visual Basic) is passed to a method that does 'not accept
it as a valid argument.
Throw New DBAccessException("You are passing a 'Nothing' as
a parameter to a method where an actual value is required.", ane)
Catch ce As ConstraintException
'Represents the exception that is thrown when attempting an
action that violates a constraint.
Throw New DBAccessException("You have attempted an action
that violates a constraint.", ce)
Catch e As Exception
'Represents errors that occur during application execution.
Throw New DBAccessException("An unanticipated exception has
ocurred.", e)
End Try
Try
_dataSet1.Tables(_currentTable).Rows.Add(row) '<<<This
line causes the error
Catch diee As Data.InvalidExpressionException
'Represents the exception that is thrown when attempting to
add a DataColumn
Throw New DBAccessException("The data column you are
attempting to add contains an error.", diee)
Catch dsee As SyntaxErrorException
'Represents the exception that is thrown when the
Expression property of a DataColumn contains a syntax error.
Throw New DBAccessException("The data column you are
attempting to add contains a syntax error.", dsee)
Catch e As Exception
MessageBox.Show("Exception Message: " & vbCrLf & e.Message)
MessageBox.Show("Exception Source: " & vbCrLf & e.Source)
MessageBox.Show("Exception StackTrace: " & vbCrLf &
e.StackTrace)
'Represents errors that occur during application execution.
'Throw New DBAccessException("An unanticipated exception
has ocurred.", e)
End Try
End Sub
//
The error says
ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child
key values (5) to exist in the parent table.
The "5" is the value that is given to the field cmSmallint06 in the
line shown here;
\\
row("cmSmallint06") = 5 'Me.cboSensorType.NSelectedValue ~ (5 =
Hall effect)
//
I don't understand why I am getting this error when I am passing the
required value. Can someone explain what might be casusing this?
(5 = Hall effect)
Please help me.
Thank you,
dbuchanan
Here is the error message;
----------------------------
Exception Message:
ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child
key values (5) to exist in the parent table.
----------------------------
I am encountering this error when I try to insert records into table
'tbl040Cmpt' using the DataSet1.Tables("Table").Rows.Add(row)
The relevant data structure goes like this the table 'tbl040Cmpt'
contains a field that stores the value from lookup table
'lkp302SensorType'.
Here is the relationship that exists in the Dataset;
\\
Me.Relations.Add("Lkp_tbl040Cmpt_lkp302SensorType",
Me.Tables("lkp302SensorType").Columns("pkSensorTypeId"),
Me.Tables("tbl040Cmpt").Columns("cmSmallint06"))
//
Here is the 'lkp302SensorType' lookup table;
\\
CREATE TABLE [lkp302SensorType] (
[pkSensorTypeId] [smallint] IDENTITY (1, 1) NOT NULL ,
[SensorType] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[Ord] [tinyint] NOT NULL CONSTRAINT [DF_lkp302SensorType_Ord] DEFAULT
(0),
[Hide] [bit] NOT NULL CONSTRAINT [DF_lkp302SensorType_Hide] DEFAULT
(0),
CONSTRAINT [PK_lkp302SensorType] PRIMARY KEY CLUSTERED
(
[pkSensorTypeId]
) WITH FILLFACTOR = 90 ON [PRIMARY]
) ON [PRIMARY]
GO
//
Here are table 'tbl040Cmpt'
\\
CREATE TABLE [tbl040Cmpt] (
[pkComponentId] [char] (36) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL CONSTRAINT [DF_tbl040Cmpt_pkComponentId] DEFAULT (newid()),
[fkDevice] [char] (36) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[fkComponentType] [int] NOT NULL ,
[ComponentDescription] [varchar] (100) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[QuanSharingConfiguration] [tinyint] NOT NULL ,
[QuanConfigured] [tinyint] NOT NULL CONSTRAINT
[DF_tbl040Cmpt_QuanConfigured] DEFAULT (0),
[QuanActuations] [tinyint] NOT NULL CONSTRAINT
[DF_tbl040Cmpt_QuanActuations] DEFAULT (1),
[cmVarchar01] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar02] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar03] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar04] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar05] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmVarchar06] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[cmNumeric01] [numeric](5, 3) NULL ,
[cmNumeric02] [numeric](5, 3) NULL ,
[cmNumeric03] [numeric](5, 3) NULL ,
[cmNumeric04] [numeric](5, 3) NULL ,
[cmNumeric05] [numeric](5, 3) NULL ,
[cmNumeric06] [numeric](5, 3) NULL ,
[cmNumeric07] [numeric](5, 3) NULL ,
[cmBit01] [bit] NULL ,
[cmBit02] [bit] NULL ,
[cmBit03] [bit] NULL ,
[cmBit04] [bit] NULL ,
[cmBit05] [bit] NULL ,
[cmBit06] [bit] NULL ,
[cmBit07] [bit] NULL ,
[cmBit08] [bit] NULL ,
[cmBit09] [bit] NULL ,
[cmBit10] [bit] NULL ,
[cmBit11] [bit] NULL ,
[cmSmallint01] [smallint] NULL ,
[cmSmallint02] [smallint] NULL ,
[cmSmallint03] [smallint] NULL ,
[cmSmallint04] [smallint] NULL ,
[cmSmallint05] [smallint] NULL ,
[cmSmallint06] [smallint] NULL ,
[cmSmallint07] [smallint] NULL ,
[cmSmallint08] [smallint] NULL ,
[cmTinyint01] [tinyint] NULL ,
[SooOrder] [numeric](5, 3) NULL ,
[SooPrecedent] [numeric](5, 3) NULL ,
[SooDelay] [numeric](5, 3) NULL ,
[SooNote] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[cmUserNote] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[cmCreatedOn] [smalldatetime] NOT NULL ,
[cmCreatedBy] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[cmEditedOn] [smalldatetime] NOT NULL ,
[cmEditedBy] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[cmrowversion] [timestamp] NOT NULL ,
CONSTRAINT [PK_tbl040Cmpt] PRIMARY KEY CLUSTERED
(
[pkComponentId]
) WITH FILLFACTOR = 90 ON [PRIMARY] ,
CONSTRAINT [FK_tbl040Cmpt_lkp202ComponentType] FOREIGN KEY
(
[fkComponentType]
) REFERENCES [lkp202ComponentType] (
[pkComponentTypeId]
),
CONSTRAINT [FK_tbl040Cmpt_tbl030Devi] FOREIGN KEY
(
[fkDevice]
) REFERENCES [tbl030Devi] (
[pkDeviceId]
) ON DELETE CASCADE NOT FOR REPLICATION
) ON [PRIMARY]
GO
//
Here is selected code that causes the error'
\\
Private Sub InsertCylnSensor(ByVal s As String)
'Create a data row (collection of fields)
Dim row As DataRow = _dataSet1.Tables(_currentTable).NewRow
'MessageBox.Show("Insert is called for: " & s)
Try
' Data entered automatically
row("pkComponentId") = Guid.NewGuid.ToString
'row("fkDevice") = _pkDeviceIdForFkAndParameter
row("fkDevice") = f030Devi._pkDeviceIdForFkAndParameter
row("fkComponentType") = 7 'Motion sensor
' ClipDriver -
Clip Driver_1 Sensor_1 _ A(??)
row("ComponentDescription") = _
Me.txtComponentDescription.Text.ToString & _
" - " & _componentTypeNameForTitleAndCmptDescrip & "_" & s
row("QuanSharingConfiguration") = 1
row("QuanConfigured") = "0" 'This will be populated
OnSave after user enters data
'TODO - f041Cyln - InsertCylnSensor - QuanActuations -
'Propagate this on to the sensors ~ is this really necessary
row("QuanActuations") = _quanOfComponentActuations
'Propagate this on to the sensors
'TODO - f041Cyln - InsertCylnSensor - row("cmVarchar04") =
"On"
row("cmVarchar04") = "On"
row("cmVarchar06") = _pkCmptIdOfParentForSensorAndParameter
'Give all other positions a FALSE value and only the proper
position a TRUE value
' This allows proper filtering
row("cmBit01") = False 'B
row("cmBit02") = False 'D
row("cmBit04") = False 'C
row("cmBit05") = False 'A
Select Case s
Case "B"
row("cmBit01") = True 'B
Case "D"
row("cmBit02") = True 'D
Case "C"
row("cmBit04") = True 'C
Case "A"
row("cmBit05") = True 'A
End Select
row("cmBit06") = True 'PNP NON
row("cmBit07") = True 'is Motion sensor
row("cmSmallint01") = 1
'Me.cboSensorVoltage.NSelectedValue ~ (1 = 24 volt)
'cmSmallint02
'cmSmallint03
'cmSmallint04
'cmSmallint05
row("cmSmallint06") = 5 'Me.cboSensorType.NSelectedValue
~ (5 = Hall effect)
'cmSmallint07
row("cmSmallint08") = 2
'Me.cboSensorConnection.NSelectedValue ~ (2 = Micro)
row("cmUserNote") = ""
row("cmCreatedOn") = Now.ToString
row("cmCreatedBy") = SystemInformation.UserName.ToString
row("cmEditedOn") = Now.ToString
row("cmEditedBy") = SystemInformation.UserName.ToString
' The following data is entered by the user - later
'row("cmVarchar01") = ucase(Me.txtSensorIOAddress.Text)
' The following data is confirmed by the user - later
'row("cmBit06") = True 'PNP NON
Catch ane As ArgumentNullException
'The exception that is thrown when a null reference
(Nothing in Visual Basic) is passed to a method that does 'not accept
it as a valid argument.
Throw New DBAccessException("You are passing a 'Nothing' as
a parameter to a method where an actual value is required.", ane)
Catch ce As ConstraintException
'Represents the exception that is thrown when attempting an
action that violates a constraint.
Throw New DBAccessException("You have attempted an action
that violates a constraint.", ce)
Catch e As Exception
'Represents errors that occur during application execution.
Throw New DBAccessException("An unanticipated exception has
ocurred.", e)
End Try
Try
_dataSet1.Tables(_currentTable).Rows.Add(row) '<<<This
line causes the error
Catch diee As Data.InvalidExpressionException
'Represents the exception that is thrown when attempting to
add a DataColumn
Throw New DBAccessException("The data column you are
attempting to add contains an error.", diee)
Catch dsee As SyntaxErrorException
'Represents the exception that is thrown when the
Expression property of a DataColumn contains a syntax error.
Throw New DBAccessException("The data column you are
attempting to add contains a syntax error.", dsee)
Catch e As Exception
MessageBox.Show("Exception Message: " & vbCrLf & e.Message)
MessageBox.Show("Exception Source: " & vbCrLf & e.Source)
MessageBox.Show("Exception StackTrace: " & vbCrLf &
e.StackTrace)
'Represents errors that occur during application execution.
'Throw New DBAccessException("An unanticipated exception
has ocurred.", e)
End Try
End Sub
//
The error says
ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child
key values (5) to exist in the parent table.
The "5" is the value that is given to the field cmSmallint06 in the
line shown here;
\\
row("cmSmallint06") = 5 'Me.cboSensorType.NSelectedValue ~ (5 =
Hall effect)
//
I don't understand why I am getting this error when I am passing the
required value. Can someone explain what might be casusing this?
(5 = Hall effect)
Please help me.
Thank you,
dbuchanan