I am developing a VB.Net WinForm app which will replace an Access application which I wrote a while ago. This app is basically combining/modifying the contents of a number of (related) tables into a new table. So I created a dataset and loaded all my "input" tables first into the dataset as datatables, and also loaded the "output" table, which at this point was an empty table with no rows, also as a datatable.
When the app comes to the point where it wants to add the first row into the "output" datatable, I have obviously not found the right syntax to create a new row in a completely emty datatable, because it gives me an exception with a index out of range, and tells me the output datatable has no rows yet. Strange enough, when I re-execute the same few lines of code which add a new row, it works, and also for all subsequent rows added. So at the end my output datatable is correctly filled, except that the first row is empty. Here is the code I use to add a new row:
nCountM = 0
' processing takes place here which selects the data to be inserted in the output datatable
nCountM = nCountM +1
' Set first field of new row
MultiTableDataSet.Tables("Out").Rows(nCountM).Item(0) = MultiTableDataSet.Tables("In1").Rows(nCount).Item("Field0")
The exception happens on the last statement in the code snippet.
I thought that, by loading the output table into the datatable, VB had the right definition of all columns (which it does have), and that therefore even a MultiTableDataSet.Tables("
.Add() would suffice, but both that syntax and the one above with New Object() do not work, but only for the very first Rows.Add call.
It's probably something very easy for you guys, but I'm still learning VB.Net and I prefer to ask than to loose time fiddling with trials and errors...
Thanks for help