@zeejay
The error is due to, you are trying to use the UNASSIGNED variable. custID string array is assigned value inside the WHILE block, this is not sure for the compiler that the code where you are assigning the value to the variable will execute. But the line 15 will surely executed and will generate Error cos the custID might be null.
To avoid this condition you can use default values to be assigned to the variables at the time of declaration.
Modify the code Line 1 to Line 10:
String[] custID = new String[0];
int z = 0;
while (thisReader.HasRows)
{
while (thisReader.Read())
{
Array.Resize<String>(ref custID,custID.Length + 1);
custID[z] = thisReader.GetString(thisReader.GetOrdinal("CustId "));
}
z++;
}
This will surely work for you.
But instead of using String[] you can also use List<String> this will help you to reduce the code and also List provides extra functionality like sort, search.
List<String> custID = new List<String>();
while (thisReader.HasRows)
{
while (thisReader.Read())
{
custID.Add(thisReader.GetString(thisReader.GetOrdi nal("CustId")););
}
}