You say this is the line of code that errors:
ds2.Tables("PurchaseDB2").Rows(inc).Item("ItemNo") = poDG.Rows.Item(i).Cells(0).Value.ToString
So you need to figure out which part is not set to an instance, or in other words, which part is null or nothing. You can do this by setting a break point and running the code. Then use QuickWatch. (highlight the part you want to look into, right click, select quickwatch). First make sure that ds2 exists. Then make sure there is really a table inside it named PurchaseDB2. Then make sure that there are rows inside that table. etc.
I noticed that you are trying to set
row(inc)
, but I don't see what/where
inc
is. Did you mean to just use the variable i here? Or perhaps the DataGridView object that you are setting it equal to doesn't have any rows and it's the
.Cells(0)
part that is not set to an object?
Also, you may want to consider using a
For Each
to iterate through tables or grids. It appears you are iterating through a datagridview in which case you could use something like this:
For Each dgvr as DataGridView Row in poDG.Rows
Next
or looping through a table:
For Each myRow as DataRow in dtMyDataTable.Rows
Next
It's just a bit easier to use than setting up those count variables. Hope this helps.