I’m struggling to understand why when I add an item to my string array “internalDives”, the method exits and there is no debug error shown.
Please, what have I done wrong here?
private void GridDataConnection()
{
using (SqlCeConnection conn = new SqlCeConnection(ConnectionString))
{
conn.Open();
using (SqlCeCommand command = new SqlCeCommand("SELECT id,divelocation,divedate,diveduration FROM loggeddives", conn))
{
SqlCeDataReader readDiveResult = command.ExecuteReader();
var diveList = new List<string[]>();
while (readDiveResult.Read())
{
string[] internalDives = new string[4];
internalDives[0] = readDiveResult.GetString(0);
internalDives[1] = readDiveResult.GetString(1);
internalDives[2] = readDiveResult.GetString(2);
internalDives[3] = readDiveResult.GetString(3);
diveList.Add(internalDives);
i++;
}
}
conn.Close();
}
}
Are you sure all columns types are string? GetString doesn’t make any conversion and suppose all columns are of type string. I suggest you to use a try catch statement for catching any
InvalidCastException.Check also that all values are instanced. You can do it with IsDBNull method.