|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Error adding rows to tablesI 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.EndCurrentEdit() If NewRecordFlag Then Try ' THIS IS WHERE THE ERROR OCCOURS Orig_Accounts.Tables("TBL_OrigAccounts").Rows.Add(NewRow) Catch DBError As Exception Console.WriteLine(DBError.Message) Exit function End Try SetNewData() NewRow = Orig_Accounts.Tables("TBL_OrigAccounts").NewRow BindControls() End If If Orig_Accounts.HasChanges(DataRowState.Modified) Then If MsgBox("Update changes to Licence " & sLicence & " ?", MsgBoxStyle.OKCancel, "Profile Update") = MsgBoxResult.OK Then Try SQL_COMMANDBUILDER.DataAdapter = SQL_DATAADAPTER SQL_COMMANDBUILDER.GetUpdateCommand() SQL_DATAADAPTER.Update(Orig_Accounts, "TBL_OrigAccounts") Orig_Accounts.AcceptChanges() Catch ex As Exception ' Tempory MsgBox(ex.Message) End Try End If Else If Orig_Accounts.HasChanges(DataRowState.Added) Then SQL_COMMANDBUILDER.DataAdapter = SQL_DATAADAPTER SQL_COMMANDBUILDER.GetUpdateCommand() SQL_DATAADAPTER.Update(Orig_Accounts, "TBL_OrigAccounts") Orig_Accounts.AcceptChanges() End If End If NewRecordFlag = False End Function You need to do this before the Rows.Add line:
NewRow = New DataRow ====================================== David McCarter www.vsdntips.com VSDN Tips & Tricks .NET Coding Standards available at: www.cafepress.com/vsdntips.20412485 Show quoteHide quote "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.EndCurrentEdit() > If NewRecordFlag Then > Try > ' THIS IS WHERE THE ERROR OCCOURS > Orig_Accounts.Tables("TBL_OrigAccounts").Rows.Add(NewRow) > Catch DBError As Exception > Console.WriteLine(DBError.Message) > Exit function > End Try > SetNewData() > NewRow = Orig_Accounts.Tables("TBL_OrigAccounts").NewRow > BindControls() > End If > If Orig_Accounts.HasChanges(DataRowState.Modified) Then > If MsgBox("Update changes to Licence " & sLicence & " ?", > MsgBoxStyle.OKCancel, "Profile Update") = MsgBoxResult.OK Then > Try > SQL_COMMANDBUILDER.DataAdapter = SQL_DATAADAPTER > SQL_COMMANDBUILDER.GetUpdateCommand() > SQL_DATAADAPTER.Update(Orig_Accounts, "TBL_OrigAccounts") > Orig_Accounts.AcceptChanges() > Catch ex As Exception > ' Tempory > MsgBox(ex.Message) > End Try > End If > Else > If Orig_Accounts.HasChanges(DataRowState.Added) Then > SQL_COMMANDBUILDER.DataAdapter = SQL_DATAADAPTER > SQL_COMMANDBUILDER.GetUpdateCommand() > SQL_DATAADAPTER.Update(Orig_Accounts, "TBL_OrigAccounts") > Orig_Accounts.AcceptChanges() > End If > End If > NewRecordFlag = False > End Function >
Space in textBox
Auto Increment Version in VB 2005 ToolBox Icon corruption VB2005 Transparent backcolor SqlDataAdapter Questions Thread safe TextWriter question How do I copy all text files into one??? eg; Shell("copy c:\CND\dr*.txt C:\CND\TestC.txx") function help please how to control/check Date datatype inputs in textobx? I Want to Extract all URL's from HTML |
|||||||||||||||||||||||