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

Problemas al actualizar en la Base de Datos Access en VB 2010

Estas en el tema de Problemas al actualizar en la Base de Datos Access en VB 2010 en el foro de .NET en Foros del Web. Tengo problema al actualizar Base De Datos Access en VB 2010 @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código vb: Ver original Imports System.Data Imports System.Data.OleDb Public Class frmInventario   ...
  #1 (permalink)  
Antiguo 29/08/2013, 17:53
Avatar de RobCo  
Fecha de Ingreso: julio-2012
Mensajes: 50
Antigüedad: 11 años, 9 meses
Puntos: 1
Problemas al actualizar en la Base de Datos Access en VB 2010

Tengo problema al actualizar Base De Datos Access en VB 2010

Código vb:
Ver original
  1. Imports System.Data
  2. Imports System.Data.OleDb
  3. Public Class frmInventario
  4.     Dim Referencia As Integer
  5.     Dim Acciones As Integer = 0
  6.     Dim BaseDeDatos As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & My.Application.Info.DirectoryPath & "\Brayalux1030.accdb")
  7.     Private Sub cmdNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNuevo.Click
  8.         CajasDeTextos(False)
  9.         Botones(False, True)
  10.         txtCodigoDelProducto.Focus()
  11.         Acciones = 1
  12.     End Sub
  13.  
  14.     Private Sub cmdSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSalir.Click
  15.         If MsgBox("¿Desea salir?", vbYesNo, "AVISO") = vbYes Then
  16.             Me.Close()
  17.         End If
  18.     End Sub
  19.  
  20.     Private Sub frmInventario_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  21.         MostrarDatosEnGrilla()
  22.         CajasDeTextos(True)
  23.         Botones(True, False)
  24.     End Sub
  25.  
  26.  
  27.     'Habilitar y Deshabilitar Cajas de Textos
  28.    Public Sub CajasDeTextos(ByVal Estado As Boolean)
  29.         txtCodigoDelProducto.ReadOnly = Estado
  30.         txtConceptoDescripcion.ReadOnly = Estado
  31.         txtPrecioUnitario.ReadOnly = Estado
  32.         txtExitencia.ReadOnly = Estado
  33.  
  34.     End Sub
  35.  
  36.     'Habilitar y Deshabilitar Botones
  37.    Public Sub Botones(ByVal Habilitar As Boolean, ByVal Deshabilitar As Boolean)
  38.         cmdNuevo.Enabled = Habilitar
  39.         cmdModificar.Enabled = Habilitar
  40.         'Boton Grabar Deshabilitado
  41.        cmdGrabar.Enabled = Deshabilitar
  42.         cmdEliminar.Enabled = Habilitar
  43.         'Boton Cancelar Deshabilitado
  44.        cmdCancelar.Enabled = Deshabilitar
  45.         'Boton Buscar Habilitado
  46.        cmdBuscar.Enabled = Habilitar
  47.     End Sub
  48.  
  49.     Public Sub LimpiarCajasDeTextos()
  50.         txtCodigoDelProducto.Text = ""
  51.         txtConceptoDescripcion.Text = ""
  52.         txtPrecioUnitario.Text = ""
  53.         txtExitencia.Text = ""
  54.  
  55.         txtCodigoDelProducto.Focus()
  56.     End Sub
  57.  
  58.     Private Sub cmdCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancelar.Click
  59.         If MsgBox("¿Esta seguro que desea cancelar?", vbYesNo, "AVISO") = vbYes Then
  60.             Botones(True, False)
  61.             LimpiarCajasDeTextos()
  62.             CajasDeTextos(True)
  63.         End If
  64.     End Sub
  65.  
  66.     Private Sub cmdGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGrabar.Click
  67.         'Validamos las cajas de textos
  68.  
  69.         If txtCodigoDelProducto.Text = "" Then MsgBox("No has ingresado RIF/C.I", vbInformation, "Ingrese RIF/C.I") : txtCodigoDelProducto().Focus() : Exit Sub
  70.         If txtConceptoDescripcion.Text = "" Then MsgBox("No has ingresado Razón Social", vbInformation, "Ingrese Razón Social") : txtConceptoDescripcion.Focus() : Exit Sub
  71.         If txtPrecioUnitario.Text = "" Then MsgBox("No has ingresado Domicilio Fiscal", vbInformation, "Ingrese Domicilio Fiscal") : txtPrecioUnitario.Focus() : Exit Sub
  72.         If txtExitencia.Text = "" Then MsgBox("No has el número de teléfono", vbInformation, "Ingrese número teléfonico") : txtExitencia.Focus() : Exit Sub
  73.         'Grabamos
  74.        If Acciones = 1 Then
  75.             Nuevo()
  76.         ElseIf Acciones = 2 Then
  77.             Modificar()
  78.  
  79.  
  80.         End If
  81.         CajasDeTextos(True)
  82.         Botones(True, False)
  83.         LimpiarCajasDeTextos()
  84.     End Sub
  85.  
  86.     Private Sub cmdModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdModificar.Click
  87.         CajasDeTextos(False)
  88.         Botones(False, True)
  89.         Acciones = 2
  90.     End Sub
  91.     Public Sub MostrarDatosEnGrilla()
  92.         Dim Datos As New OleDb.OleDbDataAdapter("SELECT * FROM Inventario", BaseDeDatos)
  93.         Dim MemoriaInterna As New DataSet
  94.         Datos.Fill(MemoriaInterna, "Inventario")
  95.         GrillaInventario.DataSource = MemoriaInterna.Tables("Inventario")
  96.         'Ocultar campo
  97.        GrillaInventario.Columns(0).Width = 0
  98.  
  99.     End Sub
  100.     Public Sub Nuevo()
  101.         Dim Insertar As New OleDb.OleDbCommand("INSERT INTO Inventario(CodigoDelProducto, ConceptoDescripcion, PrecioUnitario, Existencia) VALUES('" & txtCodigoDelProducto.Text & "','" & txtConceptoDescripcion.Text & "','" & txtPrecioUnitario.Text & "','" & txtExitencia.Text & "')", BaseDeDatos)
  102.         BaseDeDatos.Open()
  103.         Insertar.ExecuteNonQuery()
  104.         BaseDeDatos.Close()
  105.         MostrarDatosEnGrilla()
  106.         MsgBox("Se ha registrado satisfactoriamente", vbInformation, "El registro tuvo éxito")
  107.     End Sub
  108.     Public Sub Modificar()
  109.         Dim Modificar As New OleDb.OleDbCommand("UPDATE Inventario SET CodigoDelProducto='" & txtCodigoDelProducto.Text & "',ConceptoDescripcion='" & txtConceptoDescripcion.Text & "',PrecioUnitario='" & txtPrecioUnitario.Text & "',Existencia='" & txtExitencia.Text & "' WHERE Referencia='" & Trim(Referencia) & "'", BaseDeDatos)
  110.         BaseDeDatos.Open()
  111.         Modificar.ExecuteNonQuery()
  112.         BaseDeDatos.Close()
  113.         MostrarDatosEnGrilla()
  114.         MsgBox("Se ha modificado satisfactoriamente", vbInformation, "Se ha actualizado la información")
  115.     End Sub
  116.  
  117.     Private Sub GrillaInventario_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GrillaInventario.CellContentClick
  118.         Referencia = Me.GrillaInventario.Rows(e.RowIndex).Cells(0).Value()
  119.         txtReferencia.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(0).Value()
  120.         txtCodigoDelProducto.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(1).Value()
  121.         txtConceptoDescripcion.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(2).Value()
  122.         txtPrecioUnitario.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(3).Value()
  123.         txtExitencia.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(4).Value()
  124.  
  125.     End Sub
  126. End Class

El error que me muestra, cuando quiero modificar equis datos es, en el código:

Código vb:
Ver original
  1. Public Sub Modificar()
  2.         Dim Modificar As New OleDb.OleDbCommand("UPDATE Inventario SET CodigoDelProducto='" & txtCodigoDelProducto.Text & "',ConceptoDescripcion='" & txtConceptoDescripcion.Text & "',PrecioUnitario='" & txtPrecioUnitario.Text & "',Existencia='" & txtExitencia.Text & "' WHERE Referencia='" & Trim(Referencia) & "'", BaseDeDatos)
  3.         BaseDeDatos.Open()
  4.         Modificar.ExecuteNonQuery()
  5.         BaseDeDatos.Close()
  6.         MostrarDatosEnGrilla()
  7.         MsgBox("Se ha modificado satisfactoriamente", vbInformation, "Se ha actualizado la información")
  8.     End Sub

Donde el error específico es:

Código vb:
Ver original
  1. Modificar.ExecuteNonQuery()

Necesito ayuda urgente de antemano.
  #2 (permalink)  
Antiguo 29/08/2013, 17:56
Avatar de RobCo  
Fecha de Ingreso: julio-2012
Mensajes: 50
Antigüedad: 11 años, 9 meses
Puntos: 1
Respuesta: Problemas al actualizar en la Base de Datos Access en VB 2010

Cita:
Iniciado por RobCo Ver Mensaje
Tengo problema al actualizar Base De Datos Access en VB 2010

Código vb:
Ver original
  1. Imports System.Data
  2. Imports System.Data.OleDb
  3. Public Class frmInventario
  4.     Dim Referencia As Integer
  5.     Dim Acciones As Integer = 0
  6.     Dim BaseDeDatos As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & My.Application.Info.DirectoryPath & "\Brayalux1030.accdb")
  7.     Private Sub cmdNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNuevo.Click
  8.         CajasDeTextos(False)
  9.         Botones(False, True)
  10.         txtCodigoDelProducto.Focus()
  11.         Acciones = 1
  12.     End Sub
  13.  
  14.     Private Sub cmdSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSalir.Click
  15.         If MsgBox("¿Desea salir?", vbYesNo, "AVISO") = vbYes Then
  16.             Me.Close()
  17.         End If
  18.     End Sub
  19.  
  20.     Private Sub frmInventario_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  21.         MostrarDatosEnGrilla()
  22.         CajasDeTextos(True)
  23.         Botones(True, False)
  24.     End Sub
  25.  
  26.  
  27.     'Habilitar y Deshabilitar Cajas de Textos
  28.    Public Sub CajasDeTextos(ByVal Estado As Boolean)
  29.         txtCodigoDelProducto.ReadOnly = Estado
  30.         txtConceptoDescripcion.ReadOnly = Estado
  31.         txtPrecioUnitario.ReadOnly = Estado
  32.         txtExitencia.ReadOnly = Estado
  33.  
  34.     End Sub
  35.  
  36.     'Habilitar y Deshabilitar Botones
  37.    Public Sub Botones(ByVal Habilitar As Boolean, ByVal Deshabilitar As Boolean)
  38.         cmdNuevo.Enabled = Habilitar
  39.         cmdModificar.Enabled = Habilitar
  40.         'Boton Grabar Deshabilitado
  41.        cmdGrabar.Enabled = Deshabilitar
  42.         cmdEliminar.Enabled = Habilitar
  43.         'Boton Cancelar Deshabilitado
  44.        cmdCancelar.Enabled = Deshabilitar
  45.         'Boton Buscar Habilitado
  46.        cmdBuscar.Enabled = Habilitar
  47.     End Sub
  48.  
  49.     Public Sub LimpiarCajasDeTextos()
  50.         txtCodigoDelProducto.Text = ""
  51.         txtConceptoDescripcion.Text = ""
  52.         txtPrecioUnitario.Text = ""
  53.         txtExitencia.Text = ""
  54.  
  55.         txtCodigoDelProducto.Focus()
  56.     End Sub
  57.  
  58.     Private Sub cmdCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancelar.Click
  59.         If MsgBox("¿Esta seguro que desea cancelar?", vbYesNo, "AVISO") = vbYes Then
  60.             Botones(True, False)
  61.             LimpiarCajasDeTextos()
  62.             CajasDeTextos(True)
  63.         End If
  64.     End Sub
  65.  
  66.     Private Sub cmdGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGrabar.Click
  67.         'Validamos las cajas de textos
  68.  
  69.         If txtCodigoDelProducto.Text = "" Then MsgBox("No has ingresado RIF/C.I", vbInformation, "Ingrese RIF/C.I") : txtCodigoDelProducto().Focus() : Exit Sub
  70.         If txtConceptoDescripcion.Text = "" Then MsgBox("No has ingresado Razón Social", vbInformation, "Ingrese Razón Social") : txtConceptoDescripcion.Focus() : Exit Sub
  71.         If txtPrecioUnitario.Text = "" Then MsgBox("No has ingresado Domicilio Fiscal", vbInformation, "Ingrese Domicilio Fiscal") : txtPrecioUnitario.Focus() : Exit Sub
  72.         If txtExitencia.Text = "" Then MsgBox("No has el número de teléfono", vbInformation, "Ingrese número teléfonico") : txtExitencia.Focus() : Exit Sub
  73.         'Grabamos
  74.        If Acciones = 1 Then
  75.             Nuevo()
  76.         ElseIf Acciones = 2 Then
  77.             Modificar()
  78.  
  79.  
  80.         End If
  81.         CajasDeTextos(True)
  82.         Botones(True, False)
  83.         LimpiarCajasDeTextos()
  84.     End Sub
  85.  
  86.     Private Sub cmdModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdModificar.Click
  87.         CajasDeTextos(False)
  88.         Botones(False, True)
  89.         Acciones = 2
  90.     End Sub
  91.     Public Sub MostrarDatosEnGrilla()
  92.         Dim Datos As New OleDb.OleDbDataAdapter("SELECT * FROM Inventario", BaseDeDatos)
  93.         Dim MemoriaInterna As New DataSet
  94.         Datos.Fill(MemoriaInterna, "Inventario")
  95.         GrillaInventario.DataSource = MemoriaInterna.Tables("Inventario")
  96.         'Ocultar campo
  97.        GrillaInventario.Columns(0).Width = 0
  98.  
  99.     End Sub
  100.     Public Sub Nuevo()
  101.         Dim Insertar As New OleDb.OleDbCommand("INSERT INTO Inventario(CodigoDelProducto, ConceptoDescripcion, PrecioUnitario, Existencia) VALUES('" & txtCodigoDelProducto.Text & "','" & txtConceptoDescripcion.Text & "','" & txtPrecioUnitario.Text & "','" & txtExitencia.Text & "')", BaseDeDatos)
  102.         BaseDeDatos.Open()
  103.         Insertar.ExecuteNonQuery()
  104.         BaseDeDatos.Close()
  105.         MostrarDatosEnGrilla()
  106.         MsgBox("Se ha registrado satisfactoriamente", vbInformation, "El registro tuvo éxito")
  107.     End Sub
  108.     Public Sub Modificar()
  109.         Dim Modificar As New OleDb.OleDbCommand("UPDATE Inventario SET CodigoDelProducto='" & txtCodigoDelProducto.Text & "',ConceptoDescripcion='" & txtConceptoDescripcion.Text & "',PrecioUnitario='" & txtPrecioUnitario.Text & "',Existencia='" & txtExitencia.Text & "' WHERE Referencia='" & Trim(Referencia) & "'", BaseDeDatos)
  110.         BaseDeDatos.Open()
  111.         Modificar.ExecuteNonQuery()
  112.         BaseDeDatos.Close()
  113.         MostrarDatosEnGrilla()
  114.         MsgBox("Se ha modificado satisfactoriamente", vbInformation, "Se ha actualizado la información")
  115.     End Sub
  116.  
  117.     Private Sub GrillaInventario_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GrillaInventario.CellContentClick
  118.         Referencia = Me.GrillaInventario.Rows(e.RowIndex).Cells(0).Value()
  119.         txtReferencia.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(0).Value()
  120.         txtCodigoDelProducto.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(1).Value()
  121.         txtConceptoDescripcion.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(2).Value()
  122.         txtPrecioUnitario.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(3).Value()
  123.         txtExitencia.Text = Me.GrillaInventario.Rows(e.RowIndex).Cells(4).Value()
  124.  
  125.     End Sub
  126. End Class

El error que me muestra, cuando quiero modificar equis datos es, en el código:

Código vb:
Ver original
  1. Public Sub Modificar()
  2.         Dim Modificar As New OleDb.OleDbCommand("UPDATE Inventario SET CodigoDelProducto='" & txtCodigoDelProducto.Text & "',ConceptoDescripcion='" & txtConceptoDescripcion.Text & "',PrecioUnitario='" & txtPrecioUnitario.Text & "',Existencia='" & txtExitencia.Text & "' WHERE Referencia='" & Trim(Referencia) & "'", BaseDeDatos)
  3.         BaseDeDatos.Open()
  4.         Modificar.ExecuteNonQuery()
  5.         BaseDeDatos.Close()
  6.         MostrarDatosEnGrilla()
  7.         MsgBox("Se ha modificado satisfactoriamente", vbInformation, "Se ha actualizado la información")
  8.     End Sub

Donde el error específico es:

Código vb:
Ver original
  1. Modificar.ExecuteNonQuery()

Necesito ayuda urgente de antemano.
El error que me especifica es:

No se controló OleDbException

No coinciden los tipos de datos en la expresión de criterios
  #3 (permalink)  
Antiguo 30/08/2013, 08:14
Avatar de alan_69niupi  
Fecha de Ingreso: junio-2011
Mensajes: 200
Antigüedad: 12 años, 11 meses
Puntos: 17
Respuesta: Problemas al actualizar en la Base de Datos Access en VB 2010

ok.
Primero. Usa try-catch para atrapar los errores y evitar que la ejecución se corte
algo asi.
try
{
//Aqui pones toda tu consulta. y la ExecuteNonQuuery
}
Catch(Exception ex)
{
//Esta parte te muestra exactamente el tipo de error que arroja y evita que la ejecución se corte
MessageBox.Show("Error de Ejecución: "+ ex.Message);
}


lo anterior es codigo C# solo pasalo al VB.

segundo.
el error que te muestra es muy claro. ay un campo en la base de daros de algún tipo que no coincide con un tipo string por lo que veo estas pasando el valor de los textbox sin hacer un parse según el tipo de dato de la base de datos. verifica como tienes tus campos y que tipo son. y haz el parseo correspondiente a los textbox.


Saludos!!!!!
  #4 (permalink)  
Antiguo 30/08/2013, 16:14
Avatar de RobCo  
Fecha de Ingreso: julio-2012
Mensajes: 50
Antigüedad: 11 años, 9 meses
Puntos: 1
Respuesta: Problemas al actualizar en la Base de Datos Access en VB 2010

O.k gracias, lo haré >.<

Etiquetas: access, modificar, vb
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 21:53.