当前位置: 首页>>代码示例>>C#>>正文


C# SqlDataReader.GetFloat方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlDataReader.GetFloat方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataReader.GetFloat方法的具体用法?C# SqlDataReader.GetFloat怎么用?C# SqlDataReader.GetFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlDataReader的用法示例。


在下文中一共展示了SqlDataReader.GetFloat方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFloat

        public float GetFloat(SqlDataReader row, string field)
        {
            try
            {
                var i = GetField(row, field);
                if (row.IsDBNull(i)) return 0f;
                return row.GetFloat(i);

            }
            catch (Exception ex)
            {
                throw new Exception("BindingError: " + field, ex);
            }
        }
开发者ID:guylangston,项目名称:SokoSolve,代码行数:14,代码来源:DatabaseBinder.cs

示例2: PopulateEntity

        protected static void PopulateEntity(SqlDataReader reader, ServerEntity entity, Dictionary<string, PropertyInfo> propMap)
        {
            for (int i = 0; i < reader.FieldCount; i++)
            {
                String columnName = reader.GetName(i);

                // Special case for when we select a range of values with an EntityBroker, just ignore
                if (columnName.Equals("RowNum"))
                    continue;

                if (columnName.Equals("GUID"))
                {
                    Guid uid = reader.GetGuid(i);
                    entity.SetKey(new ServerEntityKey(entity.Name, uid));
                    continue;
                }

                if (columnName.Equals(entity.Name) && columnName.Contains("Enum"))
                    columnName = "Enum";

                PropertyInfo prop;
				
                if (!propMap.TryGetValue(columnName, out prop))
                    throw new EntityNotFoundException("Unable to match column to property: " + columnName, null);

                if (columnName.Contains("GUID"))
                    columnName = columnName.Replace("GUID", "Key");

                if (reader.IsDBNull(i))
                {
                    prop.SetValue(entity, null, null);
                    continue;
                }

                Type propType = prop.PropertyType;
                if (propType == typeof(String))
                    prop.SetValue(entity, reader.GetString(i), null);
                else if (propType == typeof(ServerEntityKey))
                {
                    Guid uid = reader.GetGuid(i);
                    prop.SetValue(entity, new ServerEntityKey(columnName.Replace("Key", String.Empty), uid), null);
                }
                else if (propType == typeof(DateTime))
                    prop.SetValue(entity, reader.GetDateTime(i), null);
                else if (propType == typeof(DateTime?))
                {
                    if (reader.IsDBNull(i))
                    {
                        prop.SetValue(entity, null, null);
                    }
                    else
                    {
                        prop.SetValue(entity, reader.GetDateTime(i), null);
                    }
                    
                }
                else if (propType == typeof(bool))
                    prop.SetValue(entity, reader.GetBoolean(i), null);
                else if (propType == typeof(Int32))
                    prop.SetValue(entity, reader.GetInt32(i), null);
                else if (propType == typeof(Int16))
                    prop.SetValue(entity, reader.GetInt16(i), null);
                else if (propType == typeof(double))
                    prop.SetValue(entity, reader.GetDouble(i), null);
                else if (propType == typeof(Decimal))
                    prop.SetValue(entity, reader.GetDecimal(i), null);
                else if (propType == typeof(float))
                    prop.SetValue(entity, reader.GetFloat(i), null);
                else if (propType == typeof(XmlDocument))
                {
                    SqlXml xml = reader.GetSqlXml(i);
                    if (xml!=null && !xml.IsNull)
                    {
                        XmlReader xmlReader = xml.CreateReader();
                        if (xmlReader != null)
                        {
                            XmlDocument xmlDoc = new XmlDocument();
                            xmlDoc.Load(xmlReader);
                            prop.SetValue(entity, xmlDoc, null);
                        }
                        else
                            prop.SetValue(entity, null, null);
                    }
                    else
                    {
                        prop.SetValue(entity, null, null);
                    }
                }
                else if (typeof(ServerEnum).IsAssignableFrom(propType))
                {
                    short enumVal = reader.GetInt16(i);
                    ConstructorInfo construct = prop.PropertyType.GetConstructor(new Type[0]);
                    ServerEnum val = (ServerEnum)construct.Invoke(null);
                    val.SetEnum(enumVal);
                    prop.SetValue(entity, val, null);
                }
                else
                    throw new EntityNotFoundException("Unsupported property type: " + propType, null);
            }
        }
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:100,代码来源:Broker.cs

示例3: FillCompatibleITypedSettersFromReader

        // Copy multiple fields from reader to ITypedSettersV3
        //  Assumes caller enforces that reader and setter metadata are compatible
        internal static void FillCompatibleITypedSettersFromReader( SmiEventSink_Default sink, ITypedSettersV3 setters, SmiMetaData[] metaData, SqlDataReader reader ) {
            for ( int i = 0; i < metaData.Length; i++ ) {
                if ( reader.IsDBNull(i) ) {
                    ValueUtilsSmi.SetDBNull_Unchecked( sink, setters, i );
                }
                else {
                    switch ( metaData[i].SqlDbType ) {
                        case SqlDbType.BigInt:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Int64 ) );
                            ValueUtilsSmi.SetInt64_Unchecked( sink, setters, i, reader.GetInt64(i) );
                            break;
                        case SqlDbType.Binary:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlBytes ) );
                            ValueUtilsSmi.SetSqlBytes_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0 );
                            break;
                        case SqlDbType.Bit:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Boolean ) );
                            SetBoolean_Unchecked( sink, setters, i, reader.GetBoolean(i) );
                            break;
                        case SqlDbType.Char:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlChars ) );
                            SetSqlChars_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlChars(i), 0 );
                            break;
                        case SqlDbType.DateTime:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.DateTime ) );
                            SetDateTime_Checked( sink, setters, i, metaData[i], reader.GetDateTime(i) );
                            break;
                        case SqlDbType.Decimal:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlDecimal ) );
                            SetSqlDecimal_Unchecked( sink, setters, i, reader.GetSqlDecimal(i) );
                            break;
                        case SqlDbType.Float:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Double ) );
                            SetDouble_Unchecked( sink, setters, i, reader.GetDouble(i) );
                            break;
                        case SqlDbType.Image:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlBytes ) );
                            SetSqlBytes_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0 );
                            break;
                        case SqlDbType.Int:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Int32 ) );
                            SetInt32_Unchecked( sink, setters, i, reader.GetInt32(i) );
                            break;
                        case SqlDbType.Money:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlMoney ) );
                            SetSqlMoney_Unchecked( sink, setters, i, metaData[i], reader.GetSqlMoney(i) );
                            break;
                        case SqlDbType.NChar:
                        case SqlDbType.NText:
                        case SqlDbType.NVarChar:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlChars ) );
                            SetSqlChars_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlChars(i), 0 );
                            break;
                        case SqlDbType.Real:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Single ) );
                            SetSingle_Unchecked( sink, setters, i, reader.GetFloat(i) );
                            break;
                        case SqlDbType.UniqueIdentifier:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Guid ) );
                            SetGuid_Unchecked( sink, setters, i, reader.GetGuid(i) );
                            break;
                        case SqlDbType.SmallDateTime:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.DateTime ) );
                            SetDateTime_Checked( sink, setters, i, metaData[i], reader.GetDateTime(i) );
                            break;
                        case SqlDbType.SmallInt:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Int16 ) );
                            SetInt16_Unchecked( sink, setters, i, reader.GetInt16(i) );
                            break;
                        case SqlDbType.SmallMoney:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlMoney ) );
                            SetSqlMoney_Checked( sink, setters, i, metaData[i], reader.GetSqlMoney(i) );
                            break;
                        case SqlDbType.Text:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlChars ) );
                            SetSqlChars_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlChars(i), 0 );
                            break;
                        case SqlDbType.Timestamp:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlBytes ) );
                            SetSqlBytes_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0 );
                            break;
                        case SqlDbType.TinyInt:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.Byte ) );
                            SetByte_Unchecked( sink, setters, i, reader.GetByte(i) );
                            break;
                        case SqlDbType.VarBinary:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlBytes ) );
                            SetSqlBytes_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0 );
                            break;
                        case SqlDbType.VarChar:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.String ) );
                            SetSqlChars_LengthChecked( sink, setters, i, metaData[i], reader.GetSqlChars(i), 0 );
                            break;
                        case SqlDbType.Xml:
                            Debug.Assert( CanAccessSetterDirectly( metaData[i], ExtendedClrTypeCode.SqlXml ) );
                            SetSqlXml_Unchecked( sink, setters, i, reader.GetSqlXml(i) );
                            break;
                        case SqlDbType.Variant:
//.........这里部分代码省略.........
开发者ID:uQr,项目名称:referencesource,代码行数:101,代码来源:ValueUtilsSmi.cs

示例4: CrearPublicacion

        private PublicacionEntity CrearPublicacion(SqlDataReader cursor)
        {
            PublicacionEntity publicacion = new PublicacionEntity();
            publicacion.Id_publicacion = cursor.GetInt32(cursor.GetOrdinal("Id_publicacion"));
            publicacion.Id_usr = cursor.GetInt32(cursor.GetOrdinal("Id_usr"));
            publicacion.Titulo = cursor.GetString(cursor.GetOrdinal("Titulo"));
            publicacion.Descripcion = cursor.GetString(cursor.GetOrdinal("Descripcion"));
            publicacion.PrecioD = cursor.GetFloat(cursor.GetOrdinal("PrecioD"));
            publicacion.PrecioS = cursor.GetFloat(cursor.GetOrdinal("PrecioS"));
            publicacion.PecioM = cursor.GetFloat(cursor.GetOrdinal("PecioM"));
            publicacion.FechaDesde = cursor.GetString(cursor.GetOrdinal("FechaDesde"));
             publicacion.FechaHasta = cursor.GetString(cursor.GetOrdinal("FechaHasta"));
            //publicacion.FechaHasta = cursor.GetDateTime(cursor.GetOrdinal("FechaHasta"));
            publicacion.Alquilado = cursor.GetBoolean(cursor.GetOrdinal("Alquilado"));
            publicacion.Suspendido = cursor.GetBoolean(cursor.GetOrdinal("Suspendido"));
            publicacion.Id_publicacion = cursor.GetInt32(cursor.GetOrdinal("Id_cat_lvl3"));

            return publicacion;
        }
开发者ID:LoPresto,项目名称:ProyectoWeb,代码行数:19,代码来源:PublicacionesDA.cs

示例5: GetDeal

        private static Deal GetDeal(SqlDataReader reader)
        {
            Deal deal = new Deal
            {
                Title = reader.GetString(reader.GetOrdinal("Title")).Trim(),
                DealID = reader.GetInt32(reader.GetOrdinal("DealId")),
                UserName = reader.GetString(reader.GetOrdinal("Username")).Trim(),
                Description = reader.GetString(reader.GetOrdinal("Description")).Trim(),
                Retailer = reader.GetString(reader.GetOrdinal("Retailer")).Trim(),
                Price = Math.Round(reader.GetFloat(reader.GetOrdinal("Price")), 2),
                Url = reader.GetString(reader.GetOrdinal("Url")).Trim(),
                ImageUrl = reader.GetString(reader.GetOrdinal("ImageUrl")).Trim(),
                Date = reader.GetDateTime(reader.GetOrdinal("Date")),
                Active = reader.GetBoolean(reader.GetOrdinal("Active"))
            };

            return deal;
        }
开发者ID:nathanmarlor,项目名称:DSU,代码行数:18,代码来源:DealDataAccess.cs

示例6: FillCompatibleITypedSettersFromReader

 internal static void FillCompatibleITypedSettersFromReader(SmiEventSink_Default sink, ITypedSettersV3 setters, SmiMetaData[] metaData, SqlDataReader reader)
 {
     for (int i = 0; i < metaData.Length; i++)
     {
         if (reader.IsDBNull(i))
         {
             SetDBNull_Unchecked(sink, setters, i);
             continue;
         }
         switch (metaData[i].SqlDbType)
         {
             case SqlDbType.BigInt:
             {
                 SetInt64_Unchecked(sink, setters, i, reader.GetInt64(i));
                 continue;
             }
             case SqlDbType.Binary:
             {
                 SetSqlBytes_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0);
                 continue;
             }
             case SqlDbType.Bit:
             {
                 SetBoolean_Unchecked(sink, setters, i, reader.GetBoolean(i));
                 continue;
             }
             case SqlDbType.Char:
             {
                 SetSqlChars_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlChars(i), 0);
                 continue;
             }
             case SqlDbType.DateTime:
             {
                 SetDateTime_Checked(sink, setters, i, metaData[i], reader.GetDateTime(i));
                 continue;
             }
             case SqlDbType.Decimal:
             {
                 SetSqlDecimal_Unchecked(sink, setters, i, reader.GetSqlDecimal(i));
                 continue;
             }
             case SqlDbType.Float:
             {
                 SetDouble_Unchecked(sink, setters, i, reader.GetDouble(i));
                 continue;
             }
             case SqlDbType.Image:
             {
                 SetSqlBytes_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlBytes(i), 0);
                 continue;
             }
             case SqlDbType.Int:
             {
                 SetInt32_Unchecked(sink, setters, i, reader.GetInt32(i));
                 continue;
             }
             case SqlDbType.Money:
             {
                 SetSqlMoney_Unchecked(sink, setters, i, metaData[i], reader.GetSqlMoney(i));
                 continue;
             }
             case SqlDbType.NChar:
             case SqlDbType.NText:
             case SqlDbType.NVarChar:
             {
                 SetSqlChars_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlChars(i), 0);
                 continue;
             }
             case SqlDbType.Real:
             {
                 SetSingle_Unchecked(sink, setters, i, reader.GetFloat(i));
                 continue;
             }
             case SqlDbType.UniqueIdentifier:
             {
                 SetGuid_Unchecked(sink, setters, i, reader.GetGuid(i));
                 continue;
             }
             case SqlDbType.SmallDateTime:
             {
                 SetDateTime_Checked(sink, setters, i, metaData[i], reader.GetDateTime(i));
                 continue;
             }
             case SqlDbType.SmallInt:
             {
                 SetInt16_Unchecked(sink, setters, i, reader.GetInt16(i));
                 continue;
             }
             case SqlDbType.SmallMoney:
             {
                 SetSqlMoney_Checked(sink, setters, i, metaData[i], reader.GetSqlMoney(i));
                 continue;
             }
             case SqlDbType.Text:
             {
                 SetSqlChars_LengthChecked(sink, setters, i, metaData[i], reader.GetSqlChars(i), 0);
                 continue;
             }
             case SqlDbType.Timestamp:
             {
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:ValueUtilsSmi.cs

示例7: getFieldValue

 public static double getFieldValue(SqlDataReader dr, int ind, double def)
 {
     double val = def;
     if (!dr.IsDBNull(ind))
     {
         switch (System.Type.GetTypeCode(dr.GetFieldType(ind)))
         {
             case System.TypeCode.Boolean:
                 val = (dr.GetBoolean(ind) ? 1.0 : 0.0);
                 break;
             case System.TypeCode.Int16:
                 val = System.Convert.ToDouble(dr.GetInt16(ind));
                 break;
             case System.TypeCode.Int32:
                 val = System.Convert.ToDouble(dr.GetInt32(ind));
                 break;
             case System.TypeCode.Int64:
                 val = System.Convert.ToDouble(dr.GetInt64(ind));
                 break;
             case System.TypeCode.Single:
                 val = System.Convert.ToDouble(dr.GetFloat(ind));
                 break;
             case System.TypeCode.Double:
                 val = dr.GetDouble(ind);
                 break;
             case System.TypeCode.Decimal:
                 val = System.Convert.ToDouble(dr.GetDecimal(ind));
                 break;
         }
     }
     return val;
 }
开发者ID:ranyaof,项目名称:gismaster,代码行数:32,代码来源:DBManagerSQL.cs

示例8: GetFloatTest

		public void GetFloatTest ()
		{
			cmd.CommandText = "select type_float,type_double,convert(real,null)";
			cmd.CommandText += "from numeric_family where id=1"; 
			reader = cmd.ExecuteReader ();
			reader.Read ();
			// Test for standard exceptions 
			GetMethodTests("Float");

			// Test if data is returned correctly
			Assert.AreEqual (numericRow["type_float"], reader.GetFloat(0),
				"#2 DataValidation Failed");

			// Test for standard exceptions 
			GetMethodTests("SqlSingle");

			// Test if data is returned correctly
			Assert.AreEqual (numericRow["type_float"], reader.GetSqlSingle(0).Value,
				"#2 DataValidation Failed");
			reader.Close ();
		} 
开发者ID:Profit0004,项目名称:mono,代码行数:21,代码来源:SqlDataReaderTest.cs

示例9: SqlReadyValue

        static string SqlReadyValue(string sqlBuiltString, Column column, int columnIndex, SqlDataReader reader)
        {
            if (columnIndex > 0)
                sqlBuiltString += ", ";

            if (reader[columnIndex] == null || String.IsNullOrEmpty(reader[columnIndex].ToString()))
                return sqlBuiltString += "NULL";

            switch (column.DataType.SqlDataType)
            {
                case SqlDataType.Int:
                    sqlBuiltString += reader.GetInt32(columnIndex);
                    break;
                case SqlDataType.SmallInt:
                    sqlBuiltString += reader.GetInt16(columnIndex);
                    break;
                case SqlDataType.BigInt:
                    sqlBuiltString += reader.GetInt64(columnIndex);
                    break;
                case SqlDataType.Float:
                    try
                    {
                        float floatNumber = reader.GetFloat(columnIndex);
                        sqlBuiltString += floatNumber.ToString(CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                        double doubleNumber = reader.GetDouble(columnIndex);
                        sqlBuiltString += doubleNumber.ToString(CultureInfo.InvariantCulture);

                    }
                    break;

                case SqlDataType.Decimal:
                    decimal decimalNumber = reader.GetDecimal(columnIndex);
                    sqlBuiltString += decimalNumber.ToString(CultureInfo.InvariantCulture);
                    break;

                case SqlDataType.DateTime2:
                case SqlDataType.DateTime:
                    var date = reader.GetDateTime(columnIndex);
                    sqlBuiltString += String.Format("TO_DATE('{0}', 'yyyy-mm-dd hh24:mi:ss')", date.ToString("yyyy-MM-dd HH:mm:ss"));
                    break;

                case SqlDataType.Bit:
                    var bitData = reader.GetBoolean(columnIndex);
                    sqlBuiltString += bitData == true ? "1" : "0";
                    break;

                case SqlDataType.NVarChar:
                case SqlDataType.NVarCharMax:
                case SqlDataType.VarChar:
                    sqlBuiltString += "'" + reader.GetString(columnIndex) + "'";
                    break;

                case SqlDataType.UniqueIdentifier:
                    sqlBuiltString += "'" + reader.GetGuid(columnIndex).ToString() + "'";
                    break;

                case SqlDataType.VarBinary:
                case SqlDataType.VarBinaryMax:
                    sqlBuiltString += "NULL";
                    break;
            }

            return sqlBuiltString;
        }
开发者ID:gzuri,项目名称:MSSQL2Oracle-Migration,代码行数:67,代码来源:DataExtractor.cs


注:本文中的System.Data.SqlClient.SqlDataReader.GetFloat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。