My first thought is to!string(cellTab[CellIndex].name) is wrong, if it is a char[20] you should be scanning it to find the length and slicing. Maybe [0 .. name.indexOf("\0")] or whatever. You also shouldn't be building a query by concatenation.....