Why use the GetOrdinal() Method of the SqlDataReader

前端 未结 4 2044
北海茫月
北海茫月 2020-12-16 12:55

What\'s the difference between reading a value from an SqlDataReader using this syntax:

Dim reader As SqlClient.SqlDataReader
reader(\"value\").ToString()
         


        
4条回答
  •  离开以前
    2020-12-16 13:23

    GetOrdinal performs a case-sensitive lookup first. If it fails, a second case-insensitive search is made. GetOrdinal is kana-width insensitive.Because ordinal-based lookups are more efficient than named lookups, it is inefficient to call GetOrdinal within a loop. Save time by calling GetOrdinal once and assigning the results to an integer variable for use within the loop.

    Source: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getordinal.aspx

提交回复
热议问题