Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    66

    Unanswered: commit /rollback problem

    the exeception as follow
    An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

    Additional information: Object reference not set to an instance of an object.
    my code as follow
    Dim meetError As Boolean = False
    Dim conn As Odbc.OdbcConnection
    Dim trans As Odbc.OdbcTransaction
    Dim cmd As Odbc.OdbcCommand
    Dim da As System.Data.ODBC.OdbcDataAdapter
    Dim ds As DataSet = New DataSet("dsTable")
    Dim dt As DataTable
    Dim i As Integer
    '
    Try
    conn = New Odbc.OdbcConnection(connStr)
    conn.Open()
    cmd = conn.CreateCommand
    cmd.Transaction = trans
    '
    Catch e As Odbc.OdbcException
    MsgBox("open error " & e.Message)
    meetError = True
    Return False
    End Try
    '
    'exec sql
    Try
    For i = 0 To in_stmt.GetUpperBound(0)
    cmd.CommandText = in_stmt(i).value
    da = New Odbc.OdbcDataAdapter(cmd.CommandText, conn)
    cmd.ExecuteNonQuery()
    '
    Try
    dt = New DataTable(i.ToString)
    da.Fill(dt)
    If dt.Columns.Count > 0 Then
    ds.Merge(dt)
    End If
    Catch ex As Exception
    MsgBox("merge error " & ex.Message)
    End Try
    Next
    Catch ex As Odbc.OdbcException
    MsgBox("execute error " & ex.Message)
    meetError = True
    End Try
    '
    If meetError Then
    trans.Rollback()
    Else
    trans.Commit()
    End If
    '
    'close connectoin
    '
    grd.DataSource = ds
    Try
    conn.Close()
    conn = Nothing
    Catch e As Odbc.OdbcException
    MsgBox("close error " & e.Message)
    End Try
    Return True
    thanks for help.

  2. #2
    Join Date
    Sep 2003
    Posts
    66
    I think the problem is
    can da.fill(ds) after trans.begin but before trans.commit.
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •