0

This might seem insane but I feel compelled to ask. Assume execution of select * and a resulting SqlDataReader that you read a data row and get N columns. Now read the next row. Is there any chance whatsoever that the order of the columns within these rows will be different?

Consider figure 1 from this MSDN blog. It shows each row has a unique set of column headers for each segment of column data. The Tabular Data Stream Protocol, link from that blog, confirms that there is unique COLINFO and COLMETADATA for each "cell". Why would there that be that duplication unless there is a possibility that it could be different from one row to another?

Does anyone here reference reader[name] rather than reader[int] to avoid such a potential pitfall? Or re-load an array of name/int pairs from each row in case the ordinal changes? I understand using column names is more elegant but is it "highly recommended" for larger datasets returned from a query?

TonyG
  • 1,432
  • 12
  • 31
  • from my experience, the columns order is based on how columns order in the actual table. – Kelmen Nov 27 '15 at 02:20
  • Or when we're explicit it's in the order requested by the query : ```select foo, bar, baz from ...```. But I'm wondering if there are exceptions, again curious about the duplication of schema per row. – TonyG Nov 27 '15 at 19:04
  • u asking about select *, aren't u? – Kelmen Nov 30 '15 at 07:33
  • Thanks for the follow-ups but the query isn't relevant to my question. Whether you ask for * to get the order of the fields or you ask for specific fields, I'm wondering if there is any chance at all that the ordinal position will change between records. Again, if it is perfectly consistent, why is there schema embedded in every cell of every row? – TonyG Nov 30 '15 at 08:11
  • someone created that framework/library as such, as long as u have no issue, why bother? or u can create a new one and publish it. – Kelmen Nov 30 '15 at 08:28
  • Thanks again but I don't subscribe to the concept of not asking a question until I have to deal with consequences resulting from an unknown condition. I'm trying to understand how this stuff works. Respectfully, I won't be responding to any more questions about why I'm asking a question. I'm a curious professional who wants to understand how my tools work. Thanks. – TonyG Dec 02 '15 at 21:52

0 Answers0