Visual Basic - ayuda el un insert con tablas relacionadas

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

ayuda el un insert con tablas relacionadas

Publicado por MIGUEL MATURANA (51 intervenciones) el 27/06/2006 20:12:34
bueno tengo un insert into que inserta registros a una tabla caja_chica la, cual tengo una relacion con gastos en donde me origina un problema porque me aparece un mensaje:

"no se puede agregar o cambiar registros porque se necesita un registro relacionado en la tabla gastos"

pero si saco la relacion con gastos me inserta bien lo que pasa esque no puedo sacar la relacion porque tengo datos necesarios en gastos,alguien me pude ayudar tambien voy a enviar en codigo del grabar

private sub cmd_grabar clicK()

On Error GoTo E
Dim X As Integer, cant As Long, cos As Integer, I As Integer
Dim sql1 As String

If Text1.Text = "" Or Combo8.Text = "" Or Combo7.Text = "" Or Text5.Text = "" Or Text6.Text = "" Or _
Combo1.Text = "" Or Combo2.Text = "" Or Combo3.Text = "" Or Combo6.Text = "" Or Combo5.Text = "" Or Combo4.Text = "" Then
MsgBox "DEBE INGRESAR DATOS", vbInformation
Text1.SetFocus
Exit Sub
End If

On Error GoTo H


cnn.ActiveConnection = Conex
cnn.CommandText = "INSERT INTO caja_chica VALUES('" & Trim(txt_num.Text) & "','" & UCase(Text5.Text) & "',# " & CDate(Txt_fecha.Text) & "#,'" & UCase(Text4.Text) & "','" & UCase(Text6.Text) & "','" & UCase(Text1.Text) & "','" & UCase(Combo2.Text) & "','" & UCase(Trim(Combo3.Text)) & "','" & UCase(Combo1.Text) & "','" & UCase(Trim(Combo6.Text)) & "','" & UCase(Trim(Combo7.Text)) & "','" & UCase(Combo8.Text) & "','" & UCase(Trim(Combo4.Text)) & "','" & UCase(Trim(Combo5.Text)) & "')"
cnn.Execute

/ el error lo tengo en el insert into no puedo grabar con relacion

grd1.AddItem Trim(Text1.Text) & Chr(9) & UCase(Combo1.Text) & Chr(9) & UCase(Combo2.Text) _
& Chr(9) & UCase(Trim(Text6.Text)) & Chr(9) & UCase(Trim(Text4.Text)) & Chr(9) & _
Txt_fecha.Text & Chr(9) & Trim(Text5.Text) & Chr(9) & UCase(Trim(Combo8.Text)) & Chr(9) & UCase(Trim(Combo3.Text)) _
& Chr(9) & UCase(Trim(Combo7.Text)) & Chr(9) & UCase(Trim(Combo5.Text)) & Chr(9) & _
UCase(Trim(Combo4.Text)) & Chr(9) & UCase(Trim(Combo6.Text)) _
& Chr(9) & Trim(txt_num.Text)
grd1.Refresh

cant = txt_total
cant = cant + Text5 'calculo de total de dinero ingresado en caja chica
txt_total = cant
H:
If Err.Number <> 0 Then
MsgBox Err.Description, vbInformation
Limpiar
Exit Sub
Else
Set cnn = Nothing
txt_num = txt_num + 1
deshabilitar False
Command4.Enabled = True
Command3.Enabled = True
Limpiar
Exit Sub
End If
E:
MsgBox Err.Description
end sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ayuda el un insert con tablas relacionadas

Publicado por bla (230 intervenciones) el 27/06/2006 23:38:08
Antes de realizar el insert en la tabla caja_chica, tienes que realizar otro insert en la tabla gastos para cumplir la relacción que exista entre las dos tablas.

Saldu.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar