Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/09/2006, 03:43
Avatar de SuperPinwi
SuperPinwi
 
Fecha de Ingreso: septiembre-2005
Mensajes: 317
Antigüedad: 19 años, 6 meses
Puntos: 1
Problema al actualizar un registro de una base de datos

Hola compañeros,

Tengo que actualizar un registro de una base de datos pero no lo consigo. No sé dónde estará el problema. Lo he probado a hacer de dos formas pero ninguna funciona. Adjunto un fragmento del código por si me podéis ayudar,

Muchas gracias por anticipado

Código:
Public Shared Sub EjecutaHiloActualizaBD()
        'Definir en primer lugar una referencia a System.Data.dll
        Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Super.Pinwi\Mis documentos\Mis bases de datos\numeros\numeros.mdb")
        Dim objAcciones As New OleDbCommand
        Dim dt As DataTable
        Dim objAdapter As OleDbDataAdapter = New OleDbDataAdapter
        Dim OleDbUpdateCommand As OleDbCommand = New OleDbCommand
        Dim miDataSet As New DataSet
        'Variable de bucle
        Dim i As Integer
        'Para conocer el número de filas
        Dim n As Integer
        'Cadenas temporales para nombre y numero
        Dim sNombre As String
        Dim nNumero As Integer
        'Dim sTiempo As String
        Dim dr As DataRow '= dt.Rows()
        Dim fila As Integer

        Try
            objConn.Open()
            objAdapter = New OleDbDataAdapter("SELECT * FROM numeros ORDER BY numero", objConn)
            dt = New DataTable
            objAdapter.Fill(dt)
            n = dt.Rows.Count
            objAcciones.Connection = objConn
            objAdapter.UpdateCommand = OleDbUpdateCommand

            If n = 0 Then
                MessageBox.Show("No se ha encontrado ningún registro que coincida con la selección")
            Else
                For fila = 0 To n - 1
                    dr = dt.Rows(fila)
                    OleDbUpdateCommand.CommandText = "UPDATE Numeros " & "SET numero = 5"
                    OleDbUpdateCommand.Connection = objConn
                    miDataSet.Tables("numeros").Rows(fila).Item("numero") = 8
                    objAdapter.Update(miDataSet)
                    objAdapter.Fill(miDataSet, "numeros")
                    objAdapter.Update(miDataSet)
                    dr("numero") = 9
                    'asignarDatos(dr)
                    'For i = 0 To n - 1
                    'Asignar a las variables el contenido del registro
                    sNombre = dt.Rows(i)("nombre").ToString
                    nNumero = dt.Rows(i)("numero").ToString
                Next
            End If
        Catch ex As Exception
            MessageBox.Show(Err.Description, "Información del sistema")
        End Try
    End Sub