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


C# NpgsqlParameter.ResetSqlDbType方法代码示例

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


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

示例1: ResetSqlDbType

        public void ResetSqlDbType ()
        {
            //Parameter with an assigned value but no NpgsqlDbType specified
            NpgsqlParameter p1 = new NpgsqlParameter ("foo", 42);
            Assert.AreEqual (42, p1.Value, "#1");
            Assert.AreEqual (DbType.Int32, p1.DbType, "#2");
            Assert.AreEqual (NpgsqlDbType.Integer, p1.NpgsqlDbType, "#3");

            p1.ResetSqlDbType ();
            Assert.AreEqual (DbType.Int32, p1.DbType, "#4 The parameter with value 42 must have DbType as Int32");
            Assert.AreEqual (NpgsqlDbType.Integer, p1.NpgsqlDbType, "#5 The parameter with value 42 must have NpgsqlDbType as Int");

            p1.NpgsqlDbType = NpgsqlDbType.Timestamp; //assigning a NpgsqlDbType
            Assert.AreEqual (DbType.DateTime, p1.DbType, "#6");
            Assert.AreEqual (NpgsqlDbType.Timestamp, p1.NpgsqlDbType, "#7");
            p1.ResetSqlDbType (); //Resetting NpgsqlDbType
            Assert.AreEqual (DbType.Int32, p1.DbType, "#8 Resetting NpgsqlDbType must infer the type from the value");
            Assert.AreEqual (NpgsqlDbType.Integer, p1.NpgsqlDbType, "#9 Resetting NpgsqlDbType must infer the type from the value");

            //Parameter with an assigned NpgsqlDbType but no specified value
            NpgsqlParameter p2 = new NpgsqlParameter ("foo", NpgsqlDbType.Integer);
            Assert.AreEqual (null, p2.Value, "#10");
            Assert.AreEqual (DbType.Int32, p2.DbType, "#11");
            Assert.AreEqual (NpgsqlDbType.Integer, p2.NpgsqlDbType, "#12");

            //Although a NpgsqlDbType is specified, calling ResetSqlDbType resets
            //the NpgsqlDbType and DbType properties to default values
            p2.ResetSqlDbType ();
            Assert.AreEqual (DbType.String, p2.DbType, "#13 Resetting NpgsqlDbType must infer the type from the value");
            Assert.AreEqual (NpgsqlDbType.Text, p2.NpgsqlDbType, "#14 Resetting NpgsqlDbType must infer the type from the value");

            p2.NpgsqlDbType = NpgsqlDbType.Timestamp; //assigning a NpgsqlDbType
            Assert.AreEqual (DbType.DateTime, p2.DbType, "#15");
            Assert.AreEqual (NpgsqlDbType.Timestamp, p2.NpgsqlDbType, "#16");
            p2.ResetSqlDbType (); //Resetting NpgsqlDbType
            Assert.AreEqual (DbType.String, p2.DbType, "#17 Resetting NpgsqlDbType must infer the type from the value");
            Assert.AreEqual (NpgsqlDbType.Text, p2.NpgsqlDbType, "#18 Resetting NpgsqlDbType must infer the type from the value");
        }
开发者ID:NoeGarcia,项目名称:Npgsql,代码行数:38,代码来源:NpgsqlParameterTests.cs


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