Error adding rows to tables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Newman

    #1

    Error adding rows to tables

    running vb.net 2003 & SQL 2005

    I have the following function that is meant to add a row to a table... but
    i keep getting an error and i dont understand why. Ive spent a couple of
    days on this now, has anybody any suggestions ?

    Error :-
    'row' argument cannot be null.
    Parameter name: row

    Code :-

    Private Manager As CurrencyManager
    Public sLicence As String
    Private Orig_Accounts As New DataSet
    Private NewRow As DataRow
    Private NewRecordFlag As Boolean = False



    Private Function ValidateChanges ()
    Manager.EndCurr entEdit()
    If NewRecordFlag Then
    Try
    ' THIS IS WHERE THE ERROR OCCOURS
    Orig_Accounts.T ables("TBL_Orig Accounts").Rows .Add(NewRow)
    Catch DBError As Exception
    Console.WriteLi ne(DBError.Mess age)
    Exit function
    End Try
    SetNewData()
    NewRow = Orig_Accounts.T ables("TBL_Orig Accounts").NewR ow
    BindControls()
    End If
    If Orig_Accounts.H asChanges(DataR owState.Modifie d) Then
    If MsgBox("Update changes to Licence " & sLicence & " ?",
    MsgBoxStyle.OKC ancel, "Profile Update") = MsgBoxResult.OK Then
    Try
    SQL_COMMANDBUIL DER.DataAdapter = SQL_DATAADAPTER
    SQL_COMMANDBUIL DER.GetUpdateCo mmand()
    SQL_DATAADAPTER .Update(Orig_Ac counts, "TBL_OrigAccoun ts")
    Orig_Accounts.A cceptChanges()
    Catch ex As Exception
    ' Tempory
    MsgBox(ex.Messa ge)
    End Try
    End If
    Else
    If Orig_Accounts.H asChanges(DataR owState.Added) Then
    SQL_COMMANDBUIL DER.DataAdapter = SQL_DATAADAPTER
    SQL_COMMANDBUIL DER.GetUpdateCo mmand()
    SQL_DATAADAPTER .Update(Orig_Ac counts, "TBL_OrigAccoun ts")
    Orig_Accounts.A cceptChanges()
    End If
    End If
    NewRecordFlag = False
    End Function

  • dotNetDave

    #2
    RE: Error adding rows to tables

    You need to do this before the Rows.Add line:

    NewRow = New DataRow

    =============== =============== ========
    David McCarter

    VSDN Tips & Tricks .NET Coding Standards available at:
    www.cafepress.com/vsdntips.20412485


    "Peter Newman" wrote:
    running vb.net 2003 & SQL 2005
    >
    I have the following function that is meant to add a row to a table... but
    i keep getting an error and i dont understand why. Ive spent a couple of
    days on this now, has anybody any suggestions ?
    >
    Error :-
    'row' argument cannot be null.
    Parameter name: row
    >
    Code :-
    >
    Private Manager As CurrencyManager
    Public sLicence As String
    Private Orig_Accounts As New DataSet
    Private NewRow As DataRow
    Private NewRecordFlag As Boolean = False
    >
    >
    >
    Private Function ValidateChanges ()
    Manager.EndCurr entEdit()
    If NewRecordFlag Then
    Try
    ' THIS IS WHERE THE ERROR OCCOURS
    Orig_Accounts.T ables("TBL_Orig Accounts").Rows .Add(NewRow)
    Catch DBError As Exception
    Console.WriteLi ne(DBError.Mess age)
    Exit function
    End Try
    SetNewData()
    NewRow = Orig_Accounts.T ables("TBL_Orig Accounts").NewR ow
    BindControls()
    End If
    If Orig_Accounts.H asChanges(DataR owState.Modifie d) Then
    If MsgBox("Update changes to Licence " & sLicence & " ?",
    MsgBoxStyle.OKC ancel, "Profile Update") = MsgBoxResult.OK Then
    Try
    SQL_COMMANDBUIL DER.DataAdapter = SQL_DATAADAPTER
    SQL_COMMANDBUIL DER.GetUpdateCo mmand()
    SQL_DATAADAPTER .Update(Orig_Ac counts, "TBL_OrigAccoun ts")
    Orig_Accounts.A cceptChanges()
    Catch ex As Exception
    ' Tempory
    MsgBox(ex.Messa ge)
    End Try
    End If
    Else
    If Orig_Accounts.H asChanges(DataR owState.Added) Then
    SQL_COMMANDBUIL DER.DataAdapter = SQL_DATAADAPTER
    SQL_COMMANDBUIL DER.GetUpdateCo mmand()
    SQL_DATAADAPTER .Update(Orig_Ac counts, "TBL_OrigAccoun ts")
    Orig_Accounts.A cceptChanges()
    End If
    End If
    NewRecordFlag = False
    End Function
    >

    Comment

    Working...