在使用诸如 System.Data.Odbc 或 System.Data.OracleClient 之类的命名空间时,各种数据读取器方法通常需要为函数提供与列对应的整数(例如OracleDataReader.GetInt32)。
我的问题是,使用这些函数的最佳方法是什么,以使代码具有相当的自我记录性。现在,在我看来,有三个选择,即:
// Option One - Just provide the integer value
string myString = oraData.GetString[0];
// Option Two - Provide the integer value using a constant
string myString = oraData.GetString[FIELD_NAME];
// Option Three - Provide the column name and use System.Convert to return the correct value
string myString = Convert.ToString(oraData["Field_Name"]);
这些技术中的每一种似乎都有自己的优点和缺点,我很想知道其他人的想法,或者是否有更好的方法来做到这一点。