I have two questions regarding adding rows to datatables:
First Question: When adding a new row to a datatable using the following code:
The results are as follows: The row is added (I can see that my forms binding navigator incremented), but when trying to address the new row position to write data to the table, I get an error indicating that a row does not exist at position (what ever the next position is). Oddly enough, if after adding the row, I use the binding navigator and move down one position and back up, I will not get that error when trying to write data to the new row. I am sure that it is something simple, but I just can not figure it out.Code:TblMatchDataBindingSource.CancelEdit() TblMatchDataBindingSource.AddNew() ‘This next line is where I get the error (these lines were commented out for the second test described below) Dim Row As sqlScoreBoardDBDataSet.tbl_MatchDataRow = SqlScoreBoardDBDataSet.tbl_MatchData(TblMatchDataBindingSource.Position) Row.GameIndex = int_GameIndex Call LoadScoreBoard()
Question 2: My work around for the above issue is to use the following code which works fine.
My question here is: Is this a bad way to add data rows and edit data? Is there a better more correct way to add rows to a datatable?Code:Dim myRow As DataRow = Me.SqlScoreBoardDBDataSet.tbl_MatchData.NewRow() Me.SqlScoreBoardDBDataSet.tbl_MatchData.Rows.Add(myRow) TblMatchDataBindingSource.MoveLast() ‘No error here… all is well Dim Row As sqlScoreBoardDBDataSet.tbl_MatchDataRow = SqlScoreBoardDBDataSet.tbl_MatchData(TblMatchDataBindingSource.Position) Row.GameIndex = int_GameIndex Call LoadScoreBoard()
Thanks for your help.




Reply With Quote