Foros del Web » Programación para mayores de 30 ;) » .NET »

Ayuda desesperada 2

Estas en el tema de Ayuda desesperada 2 en el foro de .NET en Foros del Web. Imports System.Data.SqlClient Public Class Form1 Private oConexion As SqlConnection Private oDataSet As DataSet Private oDataAdapter As SqlDataAdapter Private Sub Form1_Load(ByVal sender As System.Object, ByVal e ...
  #1 (permalink)  
Antiguo 06/10/2006, 10:15
(Desactivado)
 
Fecha de Ingreso: julio-2006
Mensajes: 273
Antigüedad: 17 años, 9 meses
Puntos: 5
Pregunta Ayuda desesperada 2

Imports System.Data.SqlClient

Public Class Form1

Private oConexion As SqlConnection
Private oDataSet As DataSet
Private oDataAdapter As SqlDataAdapter


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Crea una nueva conección
oConexion = New SqlConnection()
oConexion.ConnectionString = "Server=(local);Database=Inventario;uid=sa;pwd =;"

'Crea un Adaptador
oDataAdapter = New SqlDataAdapter()

'CREA COMANDOS PARA LA INSERCIÓN

Dim oCmdInsercion As New SqlCommand("DELETE * FROM Persona" & _
"(Nombre,Apellido,Edad) VALUES(@Nombre,@Apellido,@Edad)", oConexion)

oDataAdapter.DeleteCommand = oCmdInsercion
oDataAdapter.DeleteCommand.Parameters.Add(New SqlParameter("@Nombre", SqlDbType.NVarChar))
oDataAdapter.DeleteCommand.Parameters.Add(New SqlParameter("@Apellido", SqlDbType.NVarChar))
oDataAdapter.DeleteCommand.Parameters.Add(New SqlParameter("@Edad", SqlDbType.NVarChar))

'CREA COMANDOS PARA LA ELIMINACIÓN


'Crea la consulta y lo asigna al adaptador
Dim oCmdConsulta As New SqlCommand("SELECT * FROM Persona", oConexion)

oDataAdapter.SelectCommand = oCmdConsulta

'Crea un conjunto de datos
oDataSet = New DataSet()
Me.CargaDatos()
End Sub

Private Sub CargaDatos()
oDataSet.Clear()

oConexion.Open()
oDataAdapter.Fill(oDataSet, "Persona")
oConexion.Close()

Me.grdDatos.DataSource = oDataSet
Me.grdDatos.DataMember = "Persona"
End Sub

Private Sub btnBorrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrabar.Click
Dim Resultado As Integer

oDataAdapter.DeleteCommand.Parameters("@Nombre").V alue = Me.txtNombre.Text
oDataAdapter.DeleteCommand.Parameters("@Apellido") .Value = Me.txtApellido.Text
oDataAdapter.DeleteCommand.Parameters("@Edad").Val ue = Me.txtEdad.Text

oConexion.Open()
Resultado = oDataAdapter.DeleteCommand.ExecuteNonQuery()
oConexion.Close()

Me.CargaDatos()

MsgBox("REGISTRO BORRADO")
End Sub

y me dá el siguiente error

Line 1: Incorrect syntax near '*'. ¿Que diablos es eso?
  #2 (permalink)  
Antiguo 06/10/2006, 10:28
Avatar de freegirl
Colaborador
 
Fecha de Ingreso: octubre-2003
Ubicación: Catalonia
Mensajes: 4.334
Antigüedad: 20 años, 7 meses
Puntos: 156
Cita:
Dim oCmdInsercion As New SqlCommand("DELETE * FROM Persona" & _
"(Nombre,Apellido,Edad) VALUES(@Nombre,@Apellido,@Edad)", oConexion)
Esta instrucción está mal. Es una mezcla entre DELETE e INSERT INTO.

Si lo que quieres es insertar, la instrucción sql sería:

Cita:
"INSERT INTO Persona (Nombre,Apellido,Edad) VALUES (@Nombre,@Apellido,@Edad)"
saludos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:42.