This problem is usually caused by one of the following
- null values being returned for columns not set to AllowDBNull
- duplicate rows being returned with the same primary key.
- a mismatch in column definition (e.g. size of char fields) between the database and the dataset
Try running your query natively and look at the results, if the resultset is not too large. If you’ve eliminated null values, then my guess is that the primary key columns is being duplicated.
Or, to see the exact error, you can manually add a Try/Catch block to the generated code like so and then breaking when the exception is raised:
Then within the command window, call
GetErrors method on the table getting the error.
For C#, the command would be
For VB, the command is
This will show you all datarows which have an error. You can get then look at the
RowError for each of these, which should tell you the column that’s invalid along with the problem. So, to see the error of the first datarow in error the command is:
or in C# it would be