Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15714

[RESOLVED] SQLite equivalent for OleDb.OleDbRowUpdatedEventArgs

$
0
0
I have used the following to retrieve the AUTONUMBER value when adding rows (MS Access database):

Code:

Sub Row_Updated(ByVal sender As Object, ByVal e As OleDb.OleDbRowUpdatedEventArgs)

    Dim strMethodName = New System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name    '...this procedure's name

    Dim flgDebug As Boolean = False  '...debug/test purposes only
    Dim strMSG As String
    Dim lngAutoIncrement As Long

    Try
        If flgDebug Then
            Debug.WriteLine("Table = {0}, RowState = {1}, Status = {2}, StatementType = {3}", e.Row.Table.TableName, e.Row.RowState, e.Status, e.StatementType)
        End If

        For i As Integer = 0 To e.Row.Table.Columns.Count - 1
            If flgDebug Then Debug.WriteLine("{0}. {1} = {2} {3}", i, e.Row.Table.Columns(i).ColumnName, System.Type.GetType(e.Row.Table.Columns(i).DataType.ToString()), IIf(e.Row.Table.Columns(i).AutoIncrement, "AutoIncrement", ""))
            If e.Row.Table.Columns(i).AutoIncrement Then
                If e.StatementType = StatementType.Insert Then  '...we are only interested in new records
                    Using cmd As New OleDb.OleDbCommand("SELECT @@IDENTITY", e.Command.Connection)
                        lngAutoIncrement = Convert.ToInt64(cmd.ExecuteScalar)
                        e.Row(e.Row.Table.Columns(i)) = lngAutoIncrement '...fires ColumnChanged event, overwrites existing value
                    End Using
                End If
                If Not flgDebug Then Exit For
            End If
        Next i

        If flgDebug Then Debug.WriteLine("AutoNumber value (@@IDENTITY) = " & lngAutoIncrement)

        If e.Status = UpdateStatus.ErrorsOccurred Then
            strMSG = "An error has occured while updating the following row:" & vbCrLf &
                Space(4) & Chr(149) & " RecID:  " & CStr(e.Row.Item("RecID")) & vbCrLf & vbCrLf &
                e.Errors.Message & vbCrLf & vbCrLf &
                "This " & e.Row.RowState.ToString.ToLower & " row cannot be saved."
            MessageBox.Show(strMSG, strMethodName, MessageBoxButtons.OK, MessageBoxIcon.Error)
            e.Status = UpdateStatus.SkipCurrentRow
        End If

    Catch ex As Exception
        HandleError(ex, True)

    End Try

End Sub

Now I'm trying to adapt this application to use with an SQLite database.

Is this the way to do this for a SQLite database?

Viewing all articles
Browse latest Browse all 15714

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>