Ver Mensaje Individual
  #6 (permalink)  
Antiguo 15/03/2005, 10:21
Avatar de Sayra
Sayra
 
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 6 meses
Puntos: 1
Oye estuve buenisisma tu idea. El error es este ERROR: Could not add record, please ensure the fields are correctly filled outSintaxis incorrecta cerca de la palabra clave 'INNER'.
Yo cambie un poquito el codijo por que pense que el error se debia a lo mejor a que no ha bia espcificado que EstadoID, CiudadID, UbicacionID son claves en la tabla agencia y en form se seleccionan de un drop , entonces lo puse asi

Sub buttonAdd_Click(Sender As Object, E As EventArgs)
Message.InnerHtml = ""

If (Page.IsValid)

Dim DS As DataSet
Dim MyCommand As SqlCommand

Dim InsertCmd As String = "insert into Agencia (CodigoID, Agencia, Direccion, Codigo_Area, Telefono, Fax, Horario, EstadoID, CiudadID, UbicacionID, Estacionamiento, Cajero_Automatico, Autobanco, Taquilla_Externa) values (@CodigoID, @Agencia, @Direccion, @Codigo_Area, @Telefono, @Fax, @Horario, @Estado, @Ciudad, @Ubicacion, @Estacionamiento, @Cajero_Automatico, @Autobanco, @Taquilla_Externa)"
InsertCmd += " INNER JOIN Estado, Ciudad, Ubicacion"
InsertCmd += " WHERE Agencia.EstadoID=Estado.EstadoID"
InsertCmd += " AND Agencia.CiudadID=Ciudad.CiudadID"
InsertCmd += " AND Agencia.UbicacionID=Ubicacion.UbicacionID"
InsertCmd += " AND Agencia.EstadoID=" &DropDownList1.SelectedItem.Value
InsertCmd += " AND Agencia.CiudadID=" &DropDownList2.SelectedItem.Value
InsertCmd += " AND Agencia.UbicacionID=" &DropDownList3.SelectedItem.Value


MyCommand = New SqlCommand(InsertCmd, MyConnection)

MyCommand.Parameters.Add(New SqlParameter("@CodigoID", SqlDbType.NVarChar, 11))
MyCommand.Parameters("@CodigoID").Value = textBoxCodigoID.Text

MyCommand.Parameters.Add(New SqlParameter("@Agencia", SqlDbType.NVarChar, 40))
MyCommand.Parameters("@Agencia").Value = textBoxAgencia.Text

MyCommand.Parameters.Add(New SqlParameter("@Direccion", SqlDbType.NVarChar, 40))
MyCommand.Parameters("@Direccion").Value = textBoxDireccion.Text

MyCommand.Parameters.Add(New SqlParameter("@Codigo_Area", SqlDbType.NChar, 12))
MyCommand.Parameters("@Codigo_Area").Value = textBoxCodigoArea.Text

MyCommand.Parameters.Add(New SqlParameter("@Telefono", SqlDbType.NVarChar, 40))
MyCommand.Parameters("@Telefono").Value = textBoxTelefono.Text

MyCommand.Parameters.Add(New SqlParameter("@Fax", SqlDbType.NVarChar, 40))
MyCommand.Parameters("@Fax").Value = textBoxFax.Text

MyCommand.Parameters.Add(New SqlParameter("@Horario", SqlDbType.NChar, 40))
MyCommand.Parameters("@Horario").Value = textBoxHorario.Text

MyCommand.Parameters.Add(New SqlParameter("@Estado", SqlDbType.NChar, 40))
MyCommand.Parameters("@Estado").Value = DropDownList1.SelectedItem.Value

MyCommand.Parameters.Add(New SqlParameter("@Ciudad", SqlDbType.NChar,40))
MyCommand.Parameters("@Ciudad").Value = DropDownList2.SelectedItem.Value

MyCommand.Parameters.Add(New SqlParameter("@Ubicacion", SqlDbType.NChar,40))
MyCommand.Parameters("@Ubicacion").Value = DropDownList3.SelectedItem.Value

MyCommand.Parameters.Add(New SqlParameter("@Estacionamiento", SqlDbType.NChar,40))
MyCommand.Parameters("@Estacionamiento").Value = textBoxEstacio.Text

MyCommand.Parameters.Add(New SqlParameter("@Cajero_Automatico", SqlDbType.NChar,40))
MyCommand.Parameters("@Cajero_Automatico").Value = textBoxCajero.Text

MyCommand.Parameters.Add(New SqlParameter("@Autobanco", SqlDbType.NChar,40))
MyCommand.Parameters("@Autobanco").Value = textBoxAutobanco.Text

MyCommand.Parameters.Add(New SqlParameter("@Taquilla_Externa", SqlDbType.NChar,40))
MyCommand.Parameters("@Taquilla_Externa").Value = textBoxTaquilla.Text

MyCommand.Connection.Open()

Try
MyCommand.ExecuteNonQuery()
Message.InnerHtml = "<b>Record Added</b><br>" & InsertCmd.ToString()
Catch Exp As SQLException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: A record already exists with the same primary key"
Else
Message.InnerHtml = "ERROR: Could not add record, please ensure the fields are correctly filled out" &Exp.Message
End If
Message.Style("color") = "red"
End Try

MyCommand.Connection.Close()

End If
BindGrid()

End Sub