System.Data.SqlClient.SqlParameter.ResetDbType C# (CSharp) Méthode

ResetDbType() public méthode

public ResetDbType ( ) : void
Résultat void
        public override void ResetDbType()
        {
            ResetSqlDbType();
        }

Usage Example

Exemple #1
0
		public void ResetDbType ()
		{
			SqlParameter p;

			//Parameter with an assigned value but no DbType specified
			p = new SqlParameter ("foo", 42);
			p.ResetDbType ();
			Assert.AreEqual (DbType.Int32, p.DbType, "#A:DbType");
			Assert.AreEqual (SqlDbType.Int, p.SqlDbType, "#A:SqlDbType");
			Assert.AreEqual (42, p.Value, "#A:Value");

			p.DbType = DbType.DateTime; //assigning a DbType
			Assert.AreEqual (DbType.DateTime, p.DbType, "#B:DbType1");
			Assert.AreEqual (SqlDbType.DateTime, p.SqlDbType, "#B:SqlDbType1");
			p.ResetDbType ();
			Assert.AreEqual (DbType.Int32, p.DbType, "#B:DbType2");
			Assert.AreEqual (SqlDbType.Int, p.SqlDbType, "#B:SqlDbtype2");

			//Parameter with an assigned SqlDbType but no specified value
			p = new SqlParameter ("foo", SqlDbType.Int);
			p.ResetDbType ();
			Assert.AreEqual (DbType.String, p.DbType, "#C:DbType");
			Assert.AreEqual (SqlDbType.NVarChar, p.SqlDbType, "#C:SqlDbType");

			p.DbType = DbType.DateTime; //assigning a SqlDbType
			Assert.AreEqual (DbType.DateTime, p.DbType, "#D:DbType1");
			Assert.AreEqual (SqlDbType.DateTime, p.SqlDbType, "#D:SqlDbType1");
			p.ResetDbType ();
			Assert.AreEqual (DbType.String, p.DbType, "#D:DbType2");
			Assert.AreEqual (SqlDbType.NVarChar, p.SqlDbType, "#D:SqlDbType2");

			p = new SqlParameter ();
			p.Value = DateTime.MaxValue;
			Assert.AreEqual (DbType.DateTime, p.DbType, "#E:DbType1");
			Assert.AreEqual (SqlDbType.DateTime, p.SqlDbType, "#E:SqlDbType1");
			p.Value = null;
			p.ResetDbType ();
			Assert.AreEqual (DbType.String, p.DbType, "#E:DbType2");
			Assert.AreEqual (SqlDbType.NVarChar, p.SqlDbType, "#E:SqlDbType2");

			p = new SqlParameter ("foo", SqlDbType.VarChar);
			p.Value = DateTime.MaxValue;
			p.ResetDbType ();
			Assert.AreEqual (DbType.DateTime, p.DbType, "#F:DbType");
			Assert.AreEqual (SqlDbType.DateTime, p.SqlDbType, "#F:SqlDbType");
			Assert.AreEqual (DateTime.MaxValue, p.Value, "#F:Value");

			p = new SqlParameter ("foo", SqlDbType.VarChar);
			p.Value = DBNull.Value;
			p.ResetDbType ();
			Assert.AreEqual (DbType.String, p.DbType, "#G:DbType");
			Assert.AreEqual (SqlDbType.NVarChar, p.SqlDbType, "#G:SqlDbType");
			Assert.AreEqual (DBNull.Value, p.Value, "#G:Value");

			p = new SqlParameter ("foo", SqlDbType.VarChar);
			p.Value = null;
			p.ResetDbType ();
			Assert.AreEqual (DbType.String, p.DbType, "#G:DbType");
			Assert.AreEqual (SqlDbType.NVarChar, p.SqlDbType, "#G:SqlDbType");
			Assert.IsNull (p.Value, "#G:Value");
		}
All Usage Examples Of System.Data.SqlClient.SqlParameter::ResetDbType