I have a database with three pairs of tables:
TableA
TableAProspects
TableB
TableBProspects
TableC
TableCProspects
The prospects tables and their respective main tables are identical, except that the mandatory fields in the main tables are not mandatory in the prospects tables, allowing a user to supply incomplete data to the database and piece it together in multiple bits before finally submitting it to the main tables. (Upon submission to the main table the data is validated)
I've created the Select, Insert, Update and Delete queries and the TableAdapters for VB.NET have their methods set up appropriately, seethe code I've used below:
TableATableAdapter.Delete1(TableABindingSource.Current("ID"))
and
TableAProspectsTableAdapter.Delete1(TableAProspectsBindingSource.Current("ID"))
(Delete1 is the name of the method on the TableAdapters)
When I try to delete the records from the Prospects
Tables I'm recieving a System.ArgumentOutOfRangeException
with the message 'Index and length must refer to a location within the string.' when deleting record from database. This does not happen on the main tables even though the code I've used is identical except me swapping out the respective BindingSources and TableAdapters. While I understand this error message, I don't understand why I'm getting it.
I used a MsgBox to output TableABindingSource.Current("ID")
to make sure the ID was correct which it is, I've tried changing it to YProspectsClientsBindingSource.Current.Row("ID")
and then tried the latter code by setting an integer variable to this value and then using this variable
Id = TableAProspectsBindingSource.Current.Row("ID")
TableAProspectsTableAdapter.Delete1(Id)
with no success.
I've even tried deleting the TableAdapters from the form and re-inserting them.
While trying to search for answers I've found other questions which appear to be about Substrings (here and here), but I don't understand how that applies with TableAdapters, and why despite using the same code only the prospects tableadapters throw an exception.
The only differences I'm aware of are the contents of the database tables and the names of the TableAdapters and BindingSources.