Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/05/2011, 13:51
future89
 
Fecha de Ingreso: diciembre-2010
Mensajes: 106
Antigüedad: 13 años, 4 meses
Puntos: 10
insertar de visual2008 a sql2005 datos de otras tablas a una

hola, espero que me puedan ayudar con este error de la clave foranea.
tendre malo el insert?

aqui les va los datos

Esta es la base de datos:
[IMG][URL=http://imageshack.us/photo/my-images/193/11714182.jpg/][IMG]http://img193.imageshack.us/img193/9306/11714182.jpg[/IMG][/URL] [/IMG]

Este es el error
[IMG][URL=http://imageshack.us/photo/my-images/717/errorrrrrrrrrrrrrrrrrrr.jpg/][IMG=http://img717.imageshack.us/img717/5858/errorrrrrrrrrrrrrrrrrrr.jpg][/IMG][/URL] [/IMG]

Este es el código:

Código vb:
Ver original
  1. Private Sub AccionesLibros_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         myConn = New SqlConnection("Initial Catalog=libroteka;Data Source=localhost;Integrated Security=SSPI;")
  3.  
  4.         myConn.Open()
  5.         myCmd = myConn.CreateCommand
  6.         myCmd.CommandText = "SELECT * FROM editoriales"
  7.      
  8.         adaptor.SelectCommand = myCmd
  9.         adaptor.Fill(dataset)
  10.  
  11.           ' aqui le ingreso los nombre de editoriales al combobox
  12.        rut_edi.DisplayMember = "nombre_edi"
  13.         rut_edi.ValueMember = "rut_edi"
  14.         rut_edi.DataSource = dataset.Tables(0)
  15.  
  16.         myConn.Close()
  17.  
  18.         myConn = New SqlConnection("Initial Catalog=libroteka;Data Source=localhost;Integrated Security=SSPI;")
  19.  
  20.         myConn.Open()
  21.  
  22.         myCmd = myConn.CreateCommand
  23.         myCmd.CommandText = "SELECT * FROM proveedores"
  24.  
  25.  
  26.         adaptorr.SelectCommand = myCmd
  27.         adaptorr.Fill(datasett)
  28.  
  29.       ' aqui le ingreso los nombre de proveedores al combobox
  30.        rut_pro2.DisplayMember = "nombre_pro"
  31.         rut_pro2.ValueMember = "rut_pro"
  32.         rut_pro2.DataSource = datasett.Tables(0)
  33.    
  34.         myConn.Close()
  35.  
  36.     End Sub
  37.  
  38.    
  39.  
  40.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  41.         Dim NN
  42.  
  43.  
  44.  
  45.         If cod_libro.Text = "" Or nombre_libro.Text = "" Or anio_libro.Text = "" Or autor.Text = "" Or resumen.Text = "" Or categoria.Text = "" Or precio.Text = "" Or rut_pro2.Text = "" Or rut_edi.Text = "" Then
  46.  
  47.  
  48.             NN = MsgBox("Debe ingresar todos los datos.", vbExclamation, "Ingrese los datos.")
  49.         Else
  50.             dataset.Reset()
  51.             myCmd.CommandText = "SELECT * FROM libros WHERE cod_libro ='" & cod_libro.Text & "' "
  52.  
  53.  
  54.             myConn.Open()
  55.             adaptor.SelectCommand = myCmd
  56.             adaptor.Fill(dataset, "0")
  57.  
  58.             Dim count = dataset.Tables(0).Rows.Count
  59.             If count > 0 Then
  60.  
  61.                 MsgBox("libro  ya existe", MsgBoxStyle.Critical)
  62.                 myConn.Close()
  63.  
  64.             End If
  65.             dataset.Reset()
  66.             If count = 0 Then
  67.                 myConn.Close()
  68.                 myConn = New SqlConnection("Initial Catalog=libroteka;Data Source=localhost;Integrated Security=SSPI;")
  69.  
  70.  
  71.                 myCmd = myConn.CreateCommand
  72.  
  73.                 myCmd.CommandText = " INSERT INTO libros VALUES('" & cod_libro.Text & "','" & nombre_libro.Text & "','" & anio_libro.Text & "','" & autor.Text & "','" & resumen.Text & "','" & categoria.Text & "','" & precio.Text & "','" & rut_pro2.Text & "','" & rut_edi.Text & "','" & 1 & "') SELECT proveedores.rut_pro, editoriales.rut_edi FROM proveedores, editoriales WHERE proveedores.rut_pro = '" & rut_pro2.SelectedValue & "' AND editoriales.rut_edi = '" & rut_edi.SelectedValue & "' "
  74.  
  75.  
  76.  
  77.                 myConn.Open()
  78.                 myReader = myCmd.ExecuteReader()
  79.                 MsgBox("Se ha ingresado un nuevo Libro", MsgBoxStyle.Information, "Felicidades!!")
  80.  
  81.  
  82.                 myReader.Close()
  83.                 myConn.Close()
  84.             End If
  85.         End If
  86.     End Sub