18/01/2015, 22:37
|
| | Fecha de Ingreso: agosto-2010
Mensajes: 45
Antigüedad: 14 años, 2 meses Puntos: 0 | |
Respuesta: Concurrencia en ado.net Te escribi un mensaje mas arriba, el codigo imagino que es similar a este que te escribo mas abajo, que no da ningun error pero no funciona para nada, no se guardan los datos en la base de datos y tampoco se desencadena el evento rowupdate. Es todo como si nada.
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbCommandBuilder
Imports System.Data.SqlClient
Public Class Form1
Public con As New OleDbConnection
Public da As OleDbDataAdapter
Public ds As New DataSet()
Public daUpdateCommand As OleDbCommand
Public dt As DataTable
Public Event RowUpdated As SqlRowUpdatedEventHandler
Public Event RowUpdating As OleDbRowUpdatingEventHandler
Private connetionString As String
Private connection As OleDbConnection
Private adapter As OleDbDataAdapter
Private parameter As OleDbParameter
Private dataset As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
connetionString = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=C:\concurrencia\base.accdb;"
connection = New OleDbConnection(connetionString)
connection.Open()
adapter = New OleDbDataAdapter("SELECT * from tabla2", connection)
adapter.Fill(DataSet, "tabla2")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Sub OnRowUpdated(ByVal sender As Object, ByVal args As OleDbRowUpdatedEventArgs)
If args.RecordsAffected = 0 Then
args.Row.RowError = "Violacion concurrencia optimista"
args.Status = UpdateStatus.SkipCurrentRow
End If
End Sub
ACA VIENE button1_click que seria el boton que guarda la informacion de los cuadros de texto a la base de datos
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim comando As OleDbCommand = connection.CreateCommand()
adapter.UpdateCommand = New OleDbCommand("UPDATE tabla2 (nombre, apellido) VALUES(@nombre, @apellido) WHERE nombre = @oldnombre AND apellido = @oldapellido", connection)
adapter.UpdateCommand.Parameters.Add("@nombre", OleDbType.VarChar, 255).Value = txtID.Text
adapter.UpdateCommand.Parameters.Add("@apellido", OleDbType.VarChar, 255).Value = txtCharData.Text
parameter = adapter.UpdateCommand.Parameters.Add("@oldnombre", OleDbType.VarChar, 255, "nombre")
parameter.SourceVersion = DataRowVersion.Original
parameter = adapter.UpdateCommand.Parameters.Add("@oldapellido ", OleDbType.VarChar, 255, "apellido")
parameter.SourceVersion = DataRowVersion.Original
AddHandler adapter.RowUpdated, New OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated)
adapter.Update(dataset, "tabla2")
adapter.Fill(dataset, "tabla2")
Dim dataRow As DataRow
For Each dataRow In dataSet.Tables("tabla2").Rows
If dataRow.HasErrors Then
Console.WriteLine(dataRow(0) & vbCrLf & dataRow.RowError)
End If
Next
connection.Close()
Catch ex As Exception
End Try
End Sub |