SqlDataReader are these two the same Which one is faster

后端 未结 3 902
小蘑菇
小蘑菇 2021-01-20 00:45

I am working with SqlXml and the stored procedure that returns a xml rather than raw data. How does one actually read the data when returned is a xml and does not know about

3条回答
  •  悲哀的现实
    2021-01-20 01:02

    Compared to the speed of getting data from disk both will be effectively as fast as each other.

    The two calls aren't equivalent: the version with an indexer returns an object, whereas GetString() converts the object to a string, throwing an exception if this isn't possible (i.e. the column is DBNull).

    So although GetString() might be slightly slower, you'll be casting to a string anyway when you use it.

    Given all the above I'd use GetString().

提交回复
热议问题