Ver Mensaje Individual
  #4 (permalink)  
Antiguo 03/10/2012, 07:38
Avatar de DeivisAndres
DeivisAndres
 
Fecha de Ingreso: febrero-2012
Ubicación: Colombia
Mensajes: 305
Antigüedad: 12 años, 2 meses
Puntos: 41
De acuerdo Respuesta: Imposible modificar registros

Bueno, yo trabajo es en C#. pero te trate de convertir el código a VB... Lo que yo aria es crear un método que tenga el modificar con parámetros, después en el evento click del button le llamo el método y los parámetros serian los tex... quedaría de esta manera..

Código vb:
Ver original
  1. Private Function Modificar_Registros(Codigo As String, Nombre As String, Apellido As String, Email As String, Sexo As String, Edad As String) As Boolean
  2.     ' Convertir de Cadena a Numerico.
  3.     Dim Cod As Integer = Convert.ToInt32(Codigo)
  4.     Dim Ed As Integer = Convert.ToInt32(Edad)
  5.  
  6.     ' Conexión BBDD.
  7.     Dim Conexion As New OleDbConnection()
  8.     Conexion.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = G:\BBDD.accdb; Persist Security Info = false"
  9.  
  10.     ' Cadena SQL.
  11.     Dim CadenaSQL As [String] = "UPDATE Persona SET "
  12.     CadenaSQL = CadenaSQL + " Nombre = '" + Nombre + "', Apellido = '" + Apellido + "', Email = '" + Email + "', Sexo = '" + Sexo + "', Edad = " + Ed + " WHERE Id = " + Cod
  13.  
  14.     ' Crear comando.
  15.     Dim Comando As OleDbCommand = Conexion.CreateCommand()
  16.     Comando.CommandText = CadenaSQL
  17.  
  18.     Try
  19.         ' Ejecutar la consulta de acción.
  20.         Conexion.Open()
  21.         Comando.ExecuteNonQuery()
  22.         Return True
  23.     Catch ex As Exception
  24.         Dim ms As String = ex.Message
  25.         Return False
  26.     Finally
  27.         If Conexion.State = ConnectionState.Open Then
  28.             Conexion.Close()
  29.         End If
  30.     End Try
  31. End Function
  32.  
  33.  
  34. Protected Sub btnActualizar_Click(sender As Object, e As EventArgs)
  35.     If Modificar_Registros(txtCodigo.Text, txtNombre.Text, txtApellido.Text, txtEmal.Text, txtSexo.Text, txtEdad.Text) = True Then     
  36.         Response.Redirect("update.aspx?mensaje=" + "El dato se actualizo con exito.")
  37.     Else
  38.         Response.Redirect("update.aspx?mensaje=" + "El dato no se pudo actualizar.")
  39.     End If
  40. End Sub

Lo único que te quedaría seria adaptarlo al gestor de BD que utilizas... espero y te sirva...