Seems like I am stuck in ADODB days a little bit and I still expect that query with no results returns at least some meta data. Or at least my code gets no bombed by null references.SPListItemCollection has GetDataTable() method that returns items collection as ADO.NETDataTable objects. Be careful when using this method – if your items collection is empty then this method returns null.
Well, this is not an error and if you look how to use SPGridView then you get the point – you should always know what columns you expect to get from query because SPGridView doesn’t support automatic generation of fields.