RE:Foreign Key SQL SERVER
Publicado por
Enver (1 intervención) el 12/03/2008 20:01:52
a mi me pasa algo parecido pero no tengo restriccione al respecto, es un programa en vb.net asp.net 2005
aqui esta el codigo:
INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_LamReportes_GRUPO'. The conflict occurred in database 'LAMINACION', table 'GRUPO', column 'GRUPO_ID'.
The statement has been terminated.
Protected Sub GR_BUT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GR_BUT.Click
'' Verifica que los Drop's esten escogido.
If OPC2_DLL.SelectedValue.ToString = "" Then
ShowError("Por Favor Seleccione Un Turno")
OPC2_DLL.Focus()
Exit Sub
End If
If Turno_DLL.SelectedValue.ToString = "" Then
ShowError("Por Favor Seleccione Un Grupo")
Turno_DLL.Focus()
Exit Sub
End If
If DLTIPO.SelectedValue.ToString = "" Then
ShowError("Por Favor Seleccione Un Tipo")
DLTIPO.Focus()
Exit Sub
End If
If MATPRIM_DLL.SelectedValue.ToString = "" Then
ShowError("Por Favor Seleccione Una Materia")
MATPRIM_DLL.Focus()
Exit Sub
End If
If PROD_DLL.SelectedValue.ToString = "" Then
ShowError("Por Favor Seleccione Un Producto")
PROD_DLL.Focus()
Exit Sub
End If
''parte principal se guarda
Try
SMLBusinessLayer.DatatB.Guardared(ValidValue.GetValidValueInt(DLTIPO.SelectedValue), _
ValidValue.GetValidValueInt(MATPRIM_DLL.SelectedValue), ValidValue.GetValidString(PROD_DLL.SelectedValue.ToString), _
ValidValue.GetValidValueDate(TxtFecha.Text & " " & TxtHora.Text), _
ValidValue.GetValidValueInt(TxtLAmin.Text), ValidValue.GetValidDouble(TxtLH.Text), _
ValidValue.GetValidDouble(TxtPERD.Text), ValidValue.GetValidDouble(TxtATAD.Text), ValidValue.GetValidValueInt(TxtPOT.Text), _
ValidValue.GetValidValueInt(TxtCOMB.Text), ValidValue.GetValidDouble(TxtSH1.Text), _
ValidValue.GetValidDouble(TxtSH2.Text), ValidValue.GetValidDouble(TxtCMC.Text), _
ValidValue.GetValidDouble(TxtIR.Text), ValidValue.GetValidDouble(TxtPRIM.Text), _
ValidValue.GetValidDouble(TxtSeg.Text), ValidValue.GetValidDouble(TxtCUar.Text), _
ValidValue.GetValidDouble(TxtCur.Text), ValidValue.GetValidValueInt(TxtPED.Text))
Catch ex As Exception
ShowError(ex.Message)
End Try
''cabecera se guarda
Try
''aqui es donde tengo el problema en donde pide el grupo del dropdownlist.
SMLBusinessLayer.DatatB.Cargar(Me.DropDownList1.SelectedValue, ValidValue.GetValidValueDate(Me.TxtFecha.Text), Me.Turno_DLL.SelectedValue, Me.GRUPO_DLL.SelectedValue, _
Me.OPC1_DLL.SelectedValue, Me.OPH_DLL.SelectedValue, Me.OPT_DLL.SelectedValue, Me.JE_DLL.SelectedValue, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1)
Catch ex As Exception
ShowError(ex.Message)
End Try
End Sub
''la funcion.
Public Shared Function Cargar(ByVal Turno As Integer, ByVal Fecha As DateTime, ByVal Grp As Integer, ByVal OpTurno As Integer, ByVal OpCab1 As Integer, ByVal OpCab2 As Integer, ByVal OpH As Integer, ByVal JE As Integer, ByVal TC As Double, ByVal TL As Double, ByVal TE As Double, ByVal TPP As Double, ByVal TR As Double, ByVal TI As Double, ByVal TIM As Double, ByVal TIO As Double, ByVal TPPM As Double, ByVal TPPO As Double) As Integer
Dim SqlConn As SqlConnection = New SqlConnection(ConnectionStrings("LAMINACIONConnectionString").ToString)
Dim SqlCmd As New SqlClient.SqlCommand("GuardarDatosProduccion", SqlConn)
SqlCmd.CommandType = CommandType.StoredProcedure
SqlCmd.Parameters.Add("@Turno", SqlDbType.Int).Value = Turno
SqlCmd.Parameters.Add("@Fecha", SqlDbType.DateTime).Value = Fecha
SqlCmd.Parameters.Add("@Grp", SqlDbType.Int).Value = Grp
SqlCmd.Parameters.Add("@OpTurno", SqlDbType.Int).Value = IIf(OpTurno = -1, DBNull.Value, OpTurno)
SqlCmd.Parameters.Add("@OpCab1", SqlDbType.Int).Value = IIf(OpCab1 = -1, DBNull.Value, OpCab1)
SqlCmd.Parameters.Add("@OpCab2", SqlDbType.Int).Value = IIf(OpCab2 = -1, DBNull.Value, OpCab2)
SqlCmd.Parameters.Add("@OpH", SqlDbType.Int).Value = IIf(OpH = -1, DBNull.Value, OpH)
SqlCmd.Parameters.Add("@JE", SqlDbType.Int).Value = IIf(JE = -1, DBNull.Value, JE)
SqlCmd.Parameters.Add("@TC", SqlDbType.Float).Value = IIf(TC = -1, DBNull.Value, TC)
SqlCmd.Parameters.Add("@TL", SqlDbType.Float).Value = IIf(TL = -1, DBNull.Value, TL)
SqlCmd.Parameters.Add("@TE", SqlDbType.Float).Value = IIf(TE = -1, DBNull.Value, TE)
SqlCmd.Parameters.Add("@TPP", SqlDbType.Float).Value = IIf(TPP = -1, DBNull.Value, TPP)
SqlCmd.Parameters.Add("@TR", SqlDbType.Float).Value = IIf(TR = -1, DBNull.Value, TR)
SqlCmd.Parameters.Add("@TI", SqlDbType.Float).Value = IIf(TI = -1, DBNull.Value, TI)
SqlCmd.Parameters.Add("@TIM", SqlDbType.Float).Value = IIf(TIM = -1, DBNull.Value, TIM)
SqlCmd.Parameters.Add("@TIO", SqlDbType.Float).Value = IIf(TIO = -1, DBNull.Value, TIO)
SqlCmd.Parameters.Add("@TPPM", SqlDbType.Float).Value = IIf(TPPM = -1, DBNull.Value, TPPM)
SqlCmd.Parameters.Add("@TPPO", SqlDbType.Float).Value = IIf(TPPO = -1, DBNull.Value, TPPO)
SqlConn.Open()
SqlCmd.ExecuteNonQuery()
SqlConn.Close()
SqlConn.Dispose()
End Function
store procedure.
USE [LAMINACION]
GO
/****** Object: StoredProcedure [dbo].[GuardarDatosProduccion] Script Date: 03/12/2008 12:39:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GuardarDatosProduccion]
(
@Turno int,
@Fecha datetime,
@Grp int,
@OpTurno int = null,
@OpCab1 int = null,
@OpCab2 int = null,
@OpH int = null,
@JE int = null,
@TC float = null,
@TL float = null,
@TE float = null,
@TPP float = null,
@TR float = null,
@TI float = null,
@TIM float = null,
@TIO float = null,
@TPPM float = null,
@TPPO float = null
)
AS
DECLARE @Turno2 int
SELECT @Turno2 = Turno_ID FROM TURNO
BEGIN
INSERT
INTO [LAMINACION].[dbo].[LamReportes]
(
[Turno_ID],
[Fecha],
[Grupo_ID],
[OpTurno],
[OpCabina1],
[OpCabina2],
[OpHorno],
[JefeEquipo],
[TC],
[TL],
[TE],
[TPP],
[TR],
[TI],
[TIM],
[TIO],
[TPPM],
[TPPO]
)
VALUES
(
@Turno,
@Fecha,
@Grp,
@OpTurno,
@OpCab1,
@OpCab2,
@OpH,
@JE,
@TC,
@TL,
@TE,
@TPP,
@TR,
@TI,
@TIM,
@TIO,
@TPPM,
@TPPO
)
END
ESpero su Ayuda gracias