y me sale error de las claves foraneas como debe estar el insert?
Código vb:
Ver original
Private Sub AccionesLibros_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myConn = New SqlConnection("Initial Catalog=libroteka;Data Source=localhost;Integrated Security=SSPI;") myConn.Open() myCmd = myConn.CreateCommand myCmd.CommandText = "SELECT * FROM editoriales" adaptor.SelectCommand = myCmd adaptor.Fill(dataset) rut_edi.DisplayMember = "nombre_edi" rut_edi.ValueMember = "rut_edi" ' ------------clave foranea rut_edi.DataSource = dataset.Tables(0) myConn.Close() myConn = New SqlConnection("Initial Catalog=libroteka;Data Source=localhost;Integrated Security=SSPI;") myConn.Open() myCmd = myConn.CreateCommand myCmd.CommandText = "SELECT * FROM proveedores" adaptorr.SelectCommand = myCmd adaptorr.Fill(datasett) rut_pro2.DisplayMember = "nombre_pro" rut_pro2.ValueMember = "rut_pro" '---------clave foranea rut_pro2.DataSource = datasett.Tables(0) myConn.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim NN 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 NN = MsgBox("Debe ingresar todos los datos.", vbExclamation, "Ingrese los datos.") Else dataset.Reset() myCmd.CommandText = "SELECT * FROM libros WHERE cod_libro ='" & cod_libro.Text & "' " myConn.Open() adaptor.SelectCommand = myCmd adaptor.Fill(dataset, "0") Dim count = dataset.Tables(0).Rows.Count If count > 0 Then MsgBox("libro ya existe", MsgBoxStyle.Critical) myConn.Close() End If dataset.Reset() If count = 0 Then myConn.Close() myConn = New SqlConnection("Initial Catalog=libroteka;Data Source=localhost;Integrated Security=SSPI;") myCmd = myConn.CreateCommand ' ------------como guardar las claves foraneas 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.SelectedValue & "','" & rut_edi.SelectedValue & "','" & 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 & "' " myConn.Open() myReader = myCmd.ExecuteReader() MsgBox("Se ha ingresado un nuevo Libro", MsgBoxStyle.Information, "Felicidades!!") myReader.Close() myConn.Close() End If End If End Sub
esta es la base de datos