There are a couple of problems here. The most likely immediate problem is that the data is not in fact Int16
- usually Int32
(int
) is more common, so the GetInt16
is probably wrong.
Arrays are not resizeable. If you create a zero-length array, it will always be zero length. You cannot add any values to it.
I find it curious that you're reading four columns but only consuming the second one - but that won't actually cause a failure.
You only seem to actually want the first value, not all of them - is an array even needed?
There are a few things relating to disposing the reader, but they're easily fixed.
And: never ever concatenate input into SQL.
The easiest way to fix all of these is with a tool like "Dapper":
- it knows how to convert between primitive types
- it makes it easy to correctly handle readers
- it makes it easy to correctly parameterize inputs
- it makes it easy to handle results as lists, arrays, etc
int[] arr = con.Query<int>("select part2 from Table_3 where id = @id",
new { id = textBox1.Text }).ToArray();
or for just the single (first) result:
int val = con.QueryFirst<int>("select part2 from Table_3 where id = @id",
new { id = textBox1.Text });
Note: if the data is actually defined as bit
, then you'll want bool
/Boolean
in .NET.