本文整理汇总了C#中System.Data.SqlClient.SqlDataReader.GetFieldValue方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataReader.GetFieldValue方法的具体用法?C# SqlDataReader.GetFieldValue怎么用?C# SqlDataReader.GetFieldValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlDataReader
的用法示例。
在下文中一共展示了SqlDataReader.GetFieldValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TomarValorJSON
/// <summary>
/// Convierte un valor en un SqlDataReader a JSON para ser incluido en un JSN array
/// </summary>
/// <param name="Lector">Referencia hacia al lector (SqlDataReader)</param>
/// <param name="Puntero">Puntero del valor a convertir dentro del lector (SqlDataReader)</param>
/// <returns>Valor para un objeto JSON</returns>
private string TomarValorJSON(ref SqlDataReader Lector,ref short Puntero)
{
return string.Format(
"\"{0}\":{1}",
Lector.GetName(Puntero),
(Lector.IsDBNull(Puntero)) ? "null" :
((Lector.GetFieldType(Puntero) == typeof(bool) || Lector.GetFieldType(Puntero) == typeof(Boolean)) ?
((Lector.GetFieldValue<bool>(Puntero)) ? "true" : "false") :
((Lector.GetFieldType(Puntero) == typeof(int) || Lector.GetFieldType(Puntero) == typeof(byte)
|| Lector.GetFieldType(Puntero) == typeof(Int16) || Lector.GetFieldType(Puntero) == typeof(float)
|| Lector.GetFieldType(Puntero) == typeof(double)) || Lector.GetFieldType(Puntero) == typeof(decimal) ?
Lector.GetFieldValue<object>(Puntero) :
(Lector.GetFieldType(Puntero) == typeof(DateTime) ? UnixTicks(Lector.GetDateTime(Puntero)) :
"\"" + Lector.GetFieldValue<object>(Puntero)
.ToString()
.Replace("\n", "<br>")
//.Replace("\t", "\\\\u09")
.Replace("\r", "<br>")
//.Replace("\\", "\\\\u2f")
//.Replace("'", "\\\\u27")
.Replace("\"", "\\\\u22")
//.Replace("{", "\\\\u7b")
//.Replace("}", "\\\\u7e")
//.Replace("[", "\\\\u5b")
//.Replace("]", "\\\\u5d")
//.Replace(":", "\\\\u3a")
+ "\""))
)
)
;
}
示例2: ReadTransitAlert
private static TransitAlert ReadTransitAlert(SqlDataReader reader)
{
return new TransitAlert()
{
TripId = reader.GetFieldValue<string>(reader.GetOrdinal("TripId")),
StationId = reader.GetFieldValue<string>(reader.GetOrdinal("StationId")),
RouteId = reader.GetFieldValue<string>(reader.GetOrdinal("RouteId")),
RouteName = reader.GetFieldValue<string>(reader.GetOrdinal("RouteName")),
StationName = reader.GetFieldValue<string>(reader.GetOrdinal("StationName")),
ArrivalTime = reader.GetFieldValue<DateTime>(reader.GetOrdinal("ArrivalTime")),
ArrivalTimeSeconds = reader.GetFieldValue<int>(reader.GetOrdinal("ArrivalTimeSeconds")),
Direction = reader.GetFieldValue<string>(reader.GetOrdinal("Direction")),
DestinationStationId = reader.GetFieldValue<string>(reader.GetOrdinal("DestinationStationId")),
IsRealtime = reader.GetFieldValue<bool>(reader.GetOrdinal("IsRealtime")),
};
}
示例3: GetUserFromReader
// Exceptions handling
/// <summary>
/// Parse user data fields from SqlDataReader and create user data entity.
/// </summary>
/// <param name="reader">SqlDataReader with query results.</param>
/// <returns>User data entity.</returns>
private User GetUserFromReader(SqlDataReader reader)
{
/** Data columns order :
* 0 - PAROL
* 1 - DATE_E
* 2 - NIC
* 3 - KAT
*/
var expiredDate = reader.GetFieldValue<DateTime>(1);
var userName = reader.GetFieldValue<string>(2);
var userLevel = reader.GetFieldValue<int>(3);
return new User(userName, userLevel, expiredDate);
}