0

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.

Jamie
  • 47
  • 12
  • 1
    You should start by turning `Option Strict On` and fixing any errors that flags. You are obviously relying on implicit conversions being made and that can hide all sorts of issues. That error message means that a call is being made to `String.Substring` with invalid limits, so you need to work out where. Forcing explicit conversions may help but you should also have already looked at the stack trace of the exception, which will tell you what methods were executing when the exception was thrown. – jmcilhinney Apr 17 '20 at 00:47
  • Debug menu >> Exceptions window >> put a tick next to "CLR Exceptions". Run the program, screenshot the error line together with an expanded exception helper and add the shot to your question – Caius Jard Aug 05 '20 at 09:09

0 Answers0