當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。