Visual Basic.NET - Problema con update a access

 
Vista:

Problema con update a access

Publicado por mac (1 intervención) el 13/09/2007 11:42:13
Hola;

Tengo un problemilla al hacer un update en access, os cuelgo el codigo, el update me lo hace pero me da este error:
Excepción no controlada del tipo 'System.Data.OleDb.OleDbException' en system.data.dll

he pensado en poner un try catch para saltarlo pero me parece una chapuza

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim bd As New System.Data.OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=expe.mdb")
Dim com As New System.Data.OleDb.OleDbCommand("update expedientes set exp='" & nexp.Text & "',tipo='" & tipo.Text & "',empresa='" & empresa.Text & "',estado='" & estado.Text & "',trabajo='" & trabajo.Text & "',fecha='" & fecha.Text & "'", bd)
Dim i As Integer

If (nexp.Text <> "") Then
bd.Open()
i = com.ExecuteNonQuery()
MessageBox.Show("El expediente se ha actualizado correctamente", "Actualizacion correcta", MessageBoxButtons.OK, MessageBoxIcon.Information)
bd.Close()
Else
MessageBox.Show("Faltan datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub

A ver si veis alo que yo no veo
gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Problema con update a access

Publicado por Harold V. (411 intervenciones) el 13/09/2007 12:30:01
Dim Bd As New OleDb.OleDbConnection
Dim Com As New OleDb.OleDbCommand

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Bd.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=expe.mdb"
Bd.Open()

Try
Com.Connection =Bd
Com.CommandText ="Update expedientes set exp='" & nexp.Text & "',tipo='" & tipo.Text & "',empresa='" & empresa.Text & "',estado='" & estado.Text & "',trabajo='" & trabajo.Text & "',fecha='" & fecha.Text & "'"

If (nexp.Text <> "") Then
i = com.ExecuteNonQuery()
MessageBox.Show("El expediente se ha actualizado correctamente", "Actualizacion correcta", MessageBoxButtons.OK, MessageBoxIcon.Information)

Else
MessageBox.Show("Faltan datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Catch ex As Exception
MessageBox.Show(ex.Message, "Error al insertar en la base de datos", MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally
If bd.State = ConnectionState.Open Then
bd.Close()
End If
End Try

End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar