<p>It seems like IDataReader.Read() is always true at least one time (If I'm wrong about this let me know.)  So how do you tell if it has no records without just wrapping it in a try/catch?</p>

[{'answer_id': 51120, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 5, 'selected': False, 'text': "<pre><code>if(dr.Read())\n{\n   //do stuff\n}\nelse\n{\n //it's empty\n}\n</code></pre>\n\n<p>usually you'll do this though:</p>\n\n<pre><code>while(dr.Read())\n{\n}\n</code></pre>\n"}, {'answer_id': 51121, 'author': 'JamesSugrue', 'author_id': 1075, 'author_profile': 'https://Stackoverflow.com/users/1075', 'pm_score': 3, 'selected': False, 'text': '<p>Yes, if you want to use the interface then Read until false is the only way to test. If you are looking for a generic <code>IDataReader</code> implementation, you could try <code>DbDataReader</code> and use the <code>HasRows</code> property.</p>\n'}, {'answer_id': 16146731, 'author': 'Stefan Steiger', 'author_id': 155077, 'author_profile': 'https://Stackoverflow.com/users/155077', 'pm_score': 2, 'selected': False, 'text': "<p>You can just cast <code>System.Data.IDataReader</code> to <code>System.Data.Common.DbDataReader</code> </p>\n\n<pre><code>using (System.Data.IDataReader IReader = ICommand.ExecuteReader())\n{\n    if (((System.Data.Common.DbDataReader)IReader).HasRows)\n    {\n        //do stuff\n    }\n} // End Using IReader \n</code></pre>\n\n<p>It's pure evil, but it (usually) works ;) </p>\n\n<p>(assuming your instance of <code>IDataReader</code> is implemented by a custom ADO.NET provider, and not some custom silly class of yours which just implements <code>IDataReader</code> instead of deriving from <code>DbDataReader</code> [which implements <code>IDataReader</code>]).</p>\n"}, {'answer_id': 29829487, 'author': 'SimonGates', 'author_id': 387809, 'author_profile': 'https://Stackoverflow.com/users/387809', 'pm_score': 2, 'selected': False, 'text': '<p>Just stumbled across this problem and came up with this...</p>\n\n<pre><code>bool isBeforeEoF;\n\ndo\n{\n    isBeforeEoF = reader.Read();\n\n    if (isBeforeEoF)\n    {\n        yield return new Foo()\n        {\n            StreamID = (Guid)reader["ID"],\n            FileType = (string)reader["Type"],\n            Name = (string)reader["Name"],\n            RelativePath = (string)reader["RelativePath"]\n        };         \n    }\n\n} while (isBeforeEoF);\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/51113', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4541/']