Value does not fall within the expected range
I came across the above error message when I was working with SqlCeResultSets today. I was executing a query and assigning values to a SqlCeResultset to bind the resultset to a combobox. But at runtime, when the resultset was bound to the control, I got the above error. I could not figure out was causing it. My first take was to assume this was due to the fact that teh resultset was empty. But then that did not make any sense. When I looked into the code, i realized that I have created the resultset as ‘Scrollable’, when I was creating it. Then I changes the resultsetoption to ‘None’. This solved the problem. I am not sure why Scrollable resultsetoption caused this error in the first place. Any ideas would be most welcome.
I figured it out.
You cannot have a non-scrollable resultset bound to a control. If the resultset is non-scrollable, the ResultSetView property becomes null and hence your data binding does not work.
Actually the issue was somewhere else. I had bound the resultset toa combobox. And for the combobox, I had a selected index cahgned event handler, which was badly coded without any checks for the value that was selected in the combobox. Once I got that sorted out, the problem was sorted.