2 // System.Data.SqlClient.SqlParameter.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Daniel Morgan (danmorg@sc.rr.com)
7 // Tim Coleman (tim@timcoleman.com)
8 // Diego Caravana (diego@toth.it)
9 // Umadevi S (sumadevi@novell.com)
10 // Amit Biswas (amit@amitbiswas.com)
12 // (C) Ximian, Inc. 2002
13 // Copyright (C) Tim Coleman, 2002
17 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
19 // Permission is hereby granted, free of charge, to any person obtaining
20 // a copy of this software and associated documentation files (the
21 // "Software"), to deal in the Software without restriction, including
22 // without limitation the rights to use, copy, modify, merge, publish,
23 // distribute, sublicense, and/or sell copies of the Software, and to
24 // permit persons to whom the Software is furnished to do so, subject to
25 // the following conditions:
27 // The above copyright notice and this permission notice shall be
28 // included in all copies or substantial portions of the Software.
30 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 using Mono.Data.Tds.Protocol;
42 using System.ComponentModel;
44 using System.Data.Common;
45 using System.Data.SqlTypes;
46 using System.Runtime.InteropServices;
49 namespace System.Data.SqlClient {
50 [TypeConverterAttribute (typeof (SqlParameterConverter))]
52 public sealed class SqlParameter : DbParameter, IDbDataParameter, IDataParameter, ICloneable
54 public sealed class SqlParameter : MarshalByRefObject, IDbDataParameter, IDataParameter, ICloneable
59 TdsMetaParameter metaParameter;
61 SqlParameterCollection container = null;
63 ParameterDirection direction = ParameterDirection.Input;
65 bool isTypeSet = false;
69 DataRowVersion sourceVersion;
70 SqlCompareOptions compareInfo;
75 bool sourceColumnNullMapping;
76 string xmlSchemaCollectionDatabase = String.Empty;
77 string xmlSchemaCollectionOwningSchema = String.Empty;
78 string xmlSchemaCollectionName = String.Empty;
85 public SqlParameter ()
86 : this (String.Empty, SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
91 public SqlParameter (string parameterName, object value)
93 metaParameter = new TdsMetaParameter (parameterName, value);
95 metaParameter.Value = SqlTypeToFrameworkType (value);
96 sourceVersion = DataRowVersion.Current;
99 public SqlParameter (string parameterName, SqlDbType dbType)
100 : this (parameterName, dbType, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
104 public SqlParameter (string parameterName, SqlDbType dbType, int size)
105 : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
109 public SqlParameter (string parameterName, SqlDbType dbType, int size, string sourceColumn)
110 : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, sourceColumn, DataRowVersion.Current, null)
114 [EditorBrowsable (EditorBrowsableState.Advanced)]
115 public SqlParameter (string parameterName, SqlDbType dbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
117 metaParameter = new TdsMetaParameter (parameterName, size,
118 isNullable, precision,
121 if (dbType != SqlDbType.Variant)
123 metaParameter.Value = SqlTypeToFrameworkType (value);
124 Direction = direction;
125 SourceColumn = sourceColumn;
126 SourceVersion = sourceVersion;
130 public SqlParameter (string parameterName, SqlDbType dbType, int size, ParameterDirection direction, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, bool sourceColumnNullMapping, Object value, string xmlSchemaCollectionDatabase, string xmlSchemaCollectionOwningSchema, string xmlSchemaCollectionName)
131 : this (parameterName, dbType, size, direction, false, precision, scale, sourceColumn, sourceVersion, value)
133 XmlSchemaCollectionDatabase = xmlSchemaCollectionDatabase;
134 XmlSchemaCollectionOwningSchema = xmlSchemaCollectionOwningSchema;
135 XmlSchemaCollectionName = xmlSchemaCollectionName;
136 SourceColumnNullMapping = sourceColumnNullMapping;
140 // This constructor is used internally to construct a
141 // SqlParameter. The value array comes from sp_procedure_params_rowset.
142 // This is in SqlCommand.DeriveParameters.
143 internal SqlParameter (object[] dbValues)
144 : this (dbValues [3].ToString (), String.Empty)
148 Direction = ParameterDirection.Input;
150 ParameterName = (string) dbValues[3];
152 switch ((short) dbValues[5]) {
154 Direction = ParameterDirection.Input;
157 Direction = ParameterDirection.Output;
160 Direction = ParameterDirection.InputOutput;
163 Direction = ParameterDirection.ReturnValue;
166 Direction = ParameterDirection.Input;
169 IsNullable = (dbValues [8] != null &&
170 dbValues [8] != DBNull.Value) ? (bool) dbValues [8] : false;
172 if (dbValues [12] != null && dbValues [12] != DBNull.Value)
173 Precision = (byte) ((short) dbValues [12]);
175 if (dbValues [13] != null && dbValues [13] != DBNull.Value)
176 Scale = (byte) ( (short) dbValues [13]);
178 SetDbTypeName ((string) dbValues [16]);
181 #endregion // Constructors
185 // Used to ensure that only one collection can contain this
187 internal SqlParameterCollection Container {
188 get { return container; }
189 set { container = value; }
192 internal void CheckIfInitialized ()
195 throw new Exception ("all parameters to have an explicity set type");
197 if (MetaParameter.IsVariableSizeType) {
198 if (SqlDbType == SqlDbType.Decimal && Precision == 0)
199 throw new Exception ("Parameter of type 'Decimal' have an explicitly set Precision and Scale");
201 throw new Exception ("all variable length parameters to have an explicitly set non-zero Size");
205 #if ONLY_1_0 || ONLY_1_1
207 [DataSysDescription ("The parameter generic type.")]
208 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
209 [RefreshProperties (RefreshProperties.All)]
210 [DataCategory ("Data")]
217 get { return dbType; }
224 #if ONLY_1_0 || ONLY_1_1
225 [DataCategory ("Data")]
226 [DataSysDescription ("Input, output, or bidirectional parameter.")]
227 [DefaultValue (ParameterDirection.Input)]
230 [RefreshProperties (RefreshProperties.All)]
236 ParameterDirection Direction {
237 get { return direction; }
240 switch( direction ) {
241 case ParameterDirection.Output:
242 MetaParameter.Direction = TdsParameterDirection.Output;
244 case ParameterDirection.InputOutput:
245 MetaParameter.Direction = TdsParameterDirection.InputOutput;
247 case ParameterDirection.ReturnValue:
248 MetaParameter.Direction = TdsParameterDirection.ReturnValue;
254 internal TdsMetaParameter MetaParameter {
255 get { return metaParameter; }
258 #if ONLY_1_0 || ONLY_1_1
260 [DataSysDescription ("a design-time property used for strongly typed code-generation.")]
261 [DefaultValue (false)]
263 [EditorBrowsable (EditorBrowsableState.Advanced)]
270 get { return metaParameter.IsNullable; }
271 set { metaParameter.IsNullable = value; }
275 #if ONLY_1_0 || ONLY_1_1
276 [DataCategory ("Data")]
277 [DataSysDescription ("Offset in variable length data types.")]
281 [EditorBrowsable (EditorBrowsableState.Advanced)]
284 get { return offset; }
285 set { offset = value; }
288 #if ONLY_1_0 || ONLY_1_1
289 [DataSysDescription ("Name of the parameter, like '@p1'")]
296 string ParameterName {
297 get { return metaParameter.ParameterName; }
298 set { metaParameter.ParameterName = value; }
302 #if ONLY_1_0 || ONLY_1_1
303 [DataCategory ("Data")]
304 [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
306 public byte Precision {
307 get { return metaParameter.Precision; }
308 set { metaParameter.Precision = value; }
312 #if ONLY_1_0 || ONLY_1_1
313 [DataCategory ("Data")]
314 [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
317 get { return metaParameter.Scale; }
318 set { metaParameter.Scale = value; }
321 #if ONLY_1_0 || ONLY_1_1
322 [DataCategory ("Data")]
323 [DataSysDescription ("Size of variable length data types (string & arrays).")]
331 get { return metaParameter.Size; }
332 set { metaParameter.Size = value; }
335 #if ONLY_1_0 || ONLY_1_1
336 [DataCategory ("Data")]
337 [DataSysDescription ("When used by a DataAdapter.Update, the source column name that is used to find the DataSetColumn name in the ColumnMappings. This is to copy a value between the parameter and a datarow.")]
344 string SourceColumn {
345 get { return sourceColumn; }
346 set { sourceColumn = value; }
349 #if ONLY_1_0 || ONLY_1_1
350 [DataCategory ("Data")]
351 [DataSysDescription ("When used by a DataAdapter.Update (UpdateCommand only), the version of the DataRow value that is used to update the data source.")]
352 [DefaultValue (DataRowVersion.Current)]
358 DataRowVersion SourceVersion {
359 get { return sourceVersion; }
360 set { sourceVersion = value; }
363 #if ONLY_1_0 || ONLY_1_1
364 [DataCategory ("Data")]
365 [DataSysDescription ("The parameter native type.")]
366 [DefaultValue (SqlDbType.NVarChar)]
368 [RefreshProperties (RefreshProperties.All)]
370 [DbProviderSpecificTypeProperty(true)]
372 public SqlDbType SqlDbType {
373 get { return sqlDbType; }
375 SetSqlDbType (value);
380 [TypeConverterAttribute (typeof (StringConverter))]
381 #if ONLY_1_0 || ONLY_1_1
382 [DataCategory ("Data")]
383 [DataSysDescription ("Value of the parameter.")]
384 [DefaultValue (null)]
386 [RefreshProperties (RefreshProperties.All)]
393 get { return metaParameter.Value; }
396 InferSqlType (value);
397 metaParameter.Value = SqlTypeToFrameworkType (value);
403 public SqlCompareOptions CompareInfo{
404 get{ return compareInfo; }
405 set{ compareInfo = value; }
409 public int LocaleId {
410 get { return localeId; }
411 set { localeId = value; }
415 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
416 public Object SqlValue {
417 get { return sqlValue; }
418 set { sqlValue = value; }
421 public override bool SourceColumnNullMapping {
422 get { return sourceColumnNullMapping; }
423 set { sourceColumnNullMapping = value; }
426 public string XmlSchemaCollectionDatabase {
427 get { return xmlSchemaCollectionDatabase; }
428 set { xmlSchemaCollectionDatabase = (value == null ? String.Empty : value); }
431 public string XmlSchemaCollectionName {
432 get { return xmlSchemaCollectionName; }
434 xmlSchemaCollectionName = (value == null ? String.Empty : value);
438 public string XmlSchemaCollectionOwningSchema {
439 get { return xmlSchemaCollectionOwningSchema; }
441 xmlSchemaCollectionOwningSchema = (value == null ? String.Empty : value);
445 #endregion // Properties
449 object ICloneable.Clone ()
451 return new SqlParameter (ParameterName, SqlDbType, Size, Direction, IsNullable, Precision, Scale, SourceColumn, SourceVersion, Value);
454 // If the value is set without the DbType/SqlDbType being set, then we
455 // infer type information.
456 private void InferSqlType (object value)
458 if (value == null || value == DBNull.Value) {
459 SetSqlDbType (SqlDbType.NVarChar);
463 Type type = value.GetType ();
464 string exception = String.Format ("The parameter data type of {0} is invalid.", type.Name);
466 switch (type.FullName) {
468 case "System.Data.SqlTypes.SqlInt64":
469 SetSqlDbType (SqlDbType.BigInt);
471 case "System.Boolean":
472 case "System.Data.SqlTypes.SqlBoolean":
473 SetSqlDbType (SqlDbType.Bit);
475 case "System.String":
476 case "System.Data.SqlTypes.SqlString":
477 SetSqlDbType (SqlDbType.NVarChar);
479 case "System.DateTime":
480 case "System.Data.SqlTypes.SqlDateTime":
481 SetSqlDbType (SqlDbType.DateTime);
483 case "System.Decimal":
484 case "System.Data.SqlTypes.SqlDecimal":
485 SetSqlDbType (SqlDbType.Decimal);
487 case "System.Double":
488 case "System.Data.SqlTypes.SqlDouble":
489 SetSqlDbType (SqlDbType.Float);
491 case "System.Byte[]":
492 case "System.Data.SqlTypes.SqlBinary":
493 SetSqlDbType (SqlDbType.VarBinary);
496 case "System.Data.SqlTypes.SqlByte":
497 SetSqlDbType (SqlDbType.TinyInt);
500 case "System.Data.SqlTypes.SqlInt32":
501 SetSqlDbType (SqlDbType.Int);
503 case "System.Single":
504 case "System.Data.SqlTypes.Single":
505 SetSqlDbType (SqlDbType.Real);
508 case "System.Data.SqlTypes.SqlInt16":
509 SetSqlDbType (SqlDbType.SmallInt);
512 case "System.Data.SqlTypes.SqlGuid":
513 SetSqlDbType (SqlDbType.UniqueIdentifier);
516 case "System.SmallMoney":
517 case "System.Data.SqlTypes.SqlMoney":
518 SetSqlDbType (SqlDbType.Money);
520 case "System.Object":
521 SetSqlDbType (SqlDbType.Variant);
524 throw new ArgumentException (exception);
528 // When the DbType is set, we also set the SqlDbType, as well as the SQL Server
529 // string representation of the type name. If the DbType is not convertible
530 // to an SqlDbType, throw an exception.
531 private void SetDbType (DbType type)
533 string exception = String.Format ("No mapping exists from DbType {0} to a known SqlDbType.", type);
536 case DbType.AnsiString:
537 MetaParameter.TypeName = "varchar";
538 sqlDbType = SqlDbType.VarChar;
539 MetaParameter.IsVariableSizeType = true;
541 case DbType.AnsiStringFixedLength:
542 MetaParameter.TypeName = "char";
543 sqlDbType = SqlDbType.Char;
544 MetaParameter.IsVariableSizeType = true;
547 MetaParameter.TypeName = "varbinary";
548 sqlDbType = SqlDbType.VarBinary;
549 MetaParameter.IsVariableSizeType = true;
552 MetaParameter.TypeName = "bit";
553 sqlDbType = SqlDbType.Bit;
556 MetaParameter.TypeName = "tinyint";
557 sqlDbType = SqlDbType.TinyInt;
559 case DbType.Currency:
560 sqlDbType = SqlDbType.Money;
561 MetaParameter.TypeName = "money";
564 case DbType.DateTime:
565 MetaParameter.TypeName = "datetime";
566 sqlDbType = SqlDbType.DateTime;
569 MetaParameter.TypeName = "decimal";
570 sqlDbType = SqlDbType.Decimal;
573 MetaParameter.TypeName = "float";
574 sqlDbType = SqlDbType.Float;
577 MetaParameter.TypeName = "uniqueidentifier";
578 sqlDbType = SqlDbType.UniqueIdentifier;
581 MetaParameter.TypeName = "smallint";
582 sqlDbType = SqlDbType.SmallInt;
585 MetaParameter.TypeName = "int";
586 sqlDbType = SqlDbType.Int;
589 MetaParameter.TypeName = "bigint";
590 sqlDbType = SqlDbType.BigInt;
593 MetaParameter.TypeName = "sql_variant";
594 sqlDbType = SqlDbType.Variant;
597 MetaParameter.TypeName = "real";
598 sqlDbType = SqlDbType.Real;
601 MetaParameter.TypeName = "nvarchar";
602 sqlDbType = SqlDbType.NVarChar;
603 MetaParameter.IsVariableSizeType = true;
605 case DbType.StringFixedLength:
606 MetaParameter.TypeName = "nchar";
607 sqlDbType = SqlDbType.NChar;
608 MetaParameter.IsVariableSizeType = true;
611 MetaParameter.TypeName = "datetime";
612 sqlDbType = SqlDbType.DateTime;
615 throw new ArgumentException (exception);
620 // Used by internal constructor which has a SQL Server typename
621 private void SetDbTypeName (string dbTypeName)
623 switch (dbTypeName.ToLower ()) {
625 SqlDbType = SqlDbType.BigInt;
628 SqlDbType = SqlDbType.Binary;
631 SqlDbType = SqlDbType.Bit;
634 SqlDbType = SqlDbType.Char;
637 SqlDbType = SqlDbType.DateTime;
640 SqlDbType = SqlDbType.Decimal;
643 SqlDbType = SqlDbType.Float;
646 SqlDbType = SqlDbType.Image;
649 SqlDbType = SqlDbType.Int;
652 SqlDbType = SqlDbType.Money;
655 SqlDbType = SqlDbType.NChar;
658 SqlDbType = SqlDbType.NText;
661 SqlDbType = SqlDbType.NVarChar;
664 SqlDbType = SqlDbType.Real;
666 case "smalldatetime":
667 SqlDbType = SqlDbType.SmallDateTime;
670 SqlDbType = SqlDbType.SmallInt;
673 SqlDbType = SqlDbType.SmallMoney;
676 SqlDbType = SqlDbType.Text;
679 SqlDbType = SqlDbType.Timestamp;
682 SqlDbType = SqlDbType.TinyInt;
684 case "uniqueidentifier":
685 SqlDbType = SqlDbType.UniqueIdentifier;
688 SqlDbType = SqlDbType.VarBinary;
691 SqlDbType = SqlDbType.VarChar;
694 SqlDbType = SqlDbType.Variant;
697 SqlDbType = SqlDbType.Variant;
702 // When the SqlDbType is set, we also set the DbType, as well as the SQL Server
703 // string representation of the type name. If the SqlDbType is not convertible
704 // to a DbType, throw an exception.
705 internal void SetSqlDbType (SqlDbType type)
707 string exception = String.Format ("No mapping exists from SqlDbType {0} to a known DbType.", type);
710 case SqlDbType.BigInt:
711 MetaParameter.TypeName = "bigint";
712 dbType = DbType.Int64;
714 case SqlDbType.Binary:
715 MetaParameter.TypeName = "binary";
716 dbType = DbType.Binary;
717 MetaParameter.IsVariableSizeType = true;
719 case SqlDbType.Timestamp:
720 MetaParameter.TypeName = "timestamp";
721 dbType = DbType.Binary;
723 case SqlDbType.VarBinary:
724 MetaParameter.TypeName = "varbinary";
725 dbType = DbType.Binary;
726 MetaParameter.IsVariableSizeType = true;
729 MetaParameter.TypeName = "bit";
730 dbType = DbType.Boolean;
733 MetaParameter.TypeName = "char";
734 dbType = DbType.AnsiStringFixedLength;
735 MetaParameter.IsVariableSizeType = true;
737 case SqlDbType.DateTime:
738 MetaParameter.TypeName = "datetime";
739 dbType = DbType.DateTime;
741 case SqlDbType.SmallDateTime:
742 MetaParameter.TypeName = "smalldatetime";
743 dbType = DbType.DateTime;
745 case SqlDbType.Decimal:
746 MetaParameter.TypeName = "decimal";
747 dbType = DbType.Decimal;
749 case SqlDbType.Float:
750 MetaParameter.TypeName = "float";
751 dbType = DbType.Double;
753 case SqlDbType.Image:
754 MetaParameter.TypeName = "image";
755 dbType = DbType.Binary;
756 MetaParameter.IsVariableSizeType = true;
759 MetaParameter.TypeName = "int";
760 dbType = DbType.Int32;
762 case SqlDbType.Money:
763 MetaParameter.TypeName = "money";
764 dbType = DbType.Currency;
766 case SqlDbType.SmallMoney:
767 MetaParameter.TypeName = "smallmoney";
768 dbType = DbType.Currency;
770 case SqlDbType.NChar:
771 MetaParameter.TypeName = "nchar";
772 dbType = DbType.StringFixedLength;
773 MetaParameter.IsVariableSizeType = true;
775 case SqlDbType.NText:
776 MetaParameter.TypeName = "ntext";
777 dbType = DbType.String;
778 MetaParameter.IsVariableSizeType = true;
780 case SqlDbType.NVarChar:
781 MetaParameter.TypeName = "nvarchar";
782 dbType = DbType.String;
783 MetaParameter.IsVariableSizeType = true;
786 MetaParameter.TypeName = "real";
787 dbType = DbType.Single;
789 case SqlDbType.SmallInt:
790 MetaParameter.TypeName = "smallint";
791 dbType = DbType.Int16;
794 MetaParameter.TypeName = "text";
795 dbType = DbType.AnsiString;
796 MetaParameter.IsVariableSizeType = true;
798 case SqlDbType.VarChar:
799 MetaParameter.TypeName = "varchar";
800 dbType = DbType.AnsiString;
801 MetaParameter.IsVariableSizeType = true;
803 case SqlDbType.TinyInt:
804 MetaParameter.TypeName = "tinyint";
805 dbType = DbType.Byte;
807 case SqlDbType.UniqueIdentifier:
808 MetaParameter.TypeName = "uniqueidentifier";
809 dbType = DbType.Guid;
811 case SqlDbType.Variant:
812 MetaParameter.TypeName = "sql_variant";
813 dbType = DbType.Object;
816 throw new ArgumentException (exception);
821 public override string ToString()
823 return ParameterName;
826 private object SqlTypeToFrameworkType (object value)
828 if (! (value is INullable)) // if the value is not SqlType
829 return ConvertToFrameworkType (value);
831 // Map to .net type, as Mono TDS respects only types from .net
832 switch (value.GetType ().FullName) {
833 case "System.Data.SqlTypes.SqlBinary":
834 return ( (SqlBinary) value).Value;
835 case "System.Data.SqlTypes.SqlBoolean":
836 return ( (SqlBoolean) value).Value;
837 case "System.Data.SqlTypes.SqlByte":
838 return ( (SqlByte) value).Value;
839 case "System.Data.SqlTypes.SqlDateTime":
840 return ( (SqlDateTime) value).Value;
841 case "System.Data.SqlTypes.SqlDecimal":
842 return ( (SqlDecimal) value).Value;
843 case "System.Data.SqlTypes.SqlDouble":
844 return ( (SqlDouble) value).Value;
845 case "System.Data.SqlTypes.SqlGuid":
846 return ( (SqlGuid) value).Value;
847 case "System.Data.SqlTypes.SqlInt16":
848 return ( (SqlInt16) value).Value;
849 case "System.Data.SqlTypes.SqlInt32 ":
850 return ( (SqlInt32 ) value).Value;
851 case "System.Data.SqlTypes.SqlInt64":
852 return ( (SqlInt64) value).Value;
853 case "System.Data.SqlTypes.SqlMoney":
854 return ( (SqlMoney) value).Value;
855 case "System.Data.SqlTypes.SqlSingle":
856 return ( (SqlSingle) value).Value;
857 case "System.Data.SqlTypes.SqlString":
858 return ( (SqlString) value).Value;
863 internal object ConvertToFrameworkType (object value)
865 if (value == null || value == DBNull.Value)
868 case SqlDbType.BigInt :
869 return Convert.ChangeType (value, typeof (Int64));
870 case SqlDbType.Binary:
871 case SqlDbType.VarBinary:
876 return Convert.ChangeType (value, typeof (bool));
878 return Convert.ChangeType (value, typeof (Int32));
879 case SqlDbType.SmallInt :
880 return Convert.ChangeType (value, typeof (Int16));
881 case SqlDbType.TinyInt :
882 return Convert.ChangeType (value, typeof (byte));
883 case SqlDbType.Float:
884 return Convert.ChangeType (value, typeof (Double));
886 return Convert.ChangeType (value, typeof (Single));
887 case SqlDbType.Decimal:
888 return Convert.ChangeType (value, typeof (Decimal));
889 case SqlDbType.Money:
890 case SqlDbType.SmallMoney:
892 Decimal val = (Decimal)Convert.ChangeType (value, typeof (Decimal));
893 return Decimal.Round(val, 4);
895 case SqlDbType.DateTime:
896 case SqlDbType.SmallDateTime:
897 return Convert.ChangeType (value, typeof (DateTime));
898 case SqlDbType.VarChar:
899 case SqlDbType.NVarChar:
901 case SqlDbType.NChar:
903 case SqlDbType.NText:
904 return Convert.ChangeType (value, typeof (string));
905 case SqlDbType.UniqueIdentifier:
906 return Convert.ChangeType (value, typeof (Guid));
907 case SqlDbType.Variant:
908 return metaParameter.Value;
910 throw new NotImplementedException ("Type Not Supported : " + sqlDbType.ToString());
914 public override void ResetDbType ()
916 InferSqlType (metaParameter.Value);
919 public void ResetSqlDbType ()
921 InferSqlType (metaParameter.Value);
925 #endregion // Methods