private static void WriteSingleRow(System.Data.IDataRecord rdr, string[] fieldNames, JsonTextWriter jsonWriter)
 {
     jsonWriter.WriteStartObject();
     for (int p = 0; p < fieldNames.Length; p++)
     {
         jsonWriter.WritePropertyName(fieldNames[p]);
         var vl = rdr.GetValue(p);
         jsonWriter.WriteValue(vl == DBNull.Value ? null : vl);
     }
     jsonWriter.WriteEndObject();
 }
        private object GetValue(string columnName, System.Data.IDataRecord record)
        {
            object value = record.GetValue(record.GetOrdinal(columnName));

            if (value is DBNull)
            {
                return(null);
            }

            return(value);
        }
Beispiel #3
0
        /// <summary>
        /// Return whether the specified field is set to null.
        /// </summary>
        /// <param name="record">The record to get value field in</param>
        /// <param name="name">The field name to get value for.</param>
        /// <returns>true if the specified field is set to null; otherwise, false.</returns>
        public static bool IsDBNull(this System.Data.IDataRecord record, string name)
        {
            var value = record.GetValue(record.GetOrdinal(name));

            return(value == DBNull.Value);
        }
Beispiel #4
0
        /// <summary>
        /// Gets field value as boolean in specified record.
        /// </summary>
        /// <param name="record">The record to get value field in.</param>
        /// <param name="name">The field name to get value for.</param>
        /// <returns>The field value.</returns>
        public static bool GetBoolean(this System.Data.IDataRecord record, string name)
        {
            var value = record.GetValue(record.GetOrdinal(name));

            return(Convert.ToBoolean(value, CultureInfo.InvariantCulture));
        }
Beispiel #5
0
        /// <summary>
        /// Gets field value as integer in specified record.
        /// </summary>
        /// <param name="record">The record to get value field in.</param>
        /// <param name="name">The field name to get value for.</param>
        /// <returns>The field value.</returns>
        public static int GetInt32(this System.Data.IDataRecord record, string name)
        {
            var value = record.GetValue(record.GetOrdinal(name));

            return(Convert.ToInt32(value, CultureInfo.InvariantCulture));
        }