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 {
51 [TypeConverterAttribute ("System.Data.SqlClient.SqlParameter+SqlParameterConverter, " + Consts.AssemblySystem_Data)]
52 public sealed class SqlParameter : DbParameter, IDbDataParameter, IDataParameter, ICloneable
54 [TypeConverterAttribute (typeof (SqlParameterConverter))]
55 public sealed class SqlParameter : MarshalByRefObject, IDbDataParameter, IDataParameter, ICloneable
60 TdsMetaParameter metaParameter;
62 SqlParameterCollection container = null;
64 ParameterDirection direction = ParameterDirection.Input;
66 bool isTypeSet = false;
70 DataRowVersion sourceVersion;
71 SqlCompareOptions compareInfo;
76 bool sourceColumnNullMapping;
77 string xmlSchemaCollectionDatabase = String.Empty;
78 string xmlSchemaCollectionOwningSchema = String.Empty;
79 string xmlSchemaCollectionName = String.Empty;
86 public SqlParameter ()
87 : this (String.Empty, SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
92 public SqlParameter (string parameterName, object value)
94 metaParameter = new TdsMetaParameter (parameterName, value);
96 metaParameter.Value = SqlTypeToFrameworkType (value);
97 sourceVersion = DataRowVersion.Current;
100 public SqlParameter (string parameterName, SqlDbType dbType)
101 : this (parameterName, dbType, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
105 public SqlParameter (string parameterName, SqlDbType dbType, int size)
106 : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
110 public SqlParameter (string parameterName, SqlDbType dbType, int size, string sourceColumn)
111 : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, sourceColumn, DataRowVersion.Current, null)
115 [EditorBrowsable (EditorBrowsableState.Advanced)]
116 public SqlParameter (string parameterName, SqlDbType dbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
118 metaParameter = new TdsMetaParameter (parameterName, size,
119 isNullable, precision,
122 if (dbType != SqlDbType.Variant)
124 metaParameter.Value = SqlTypeToFrameworkType (value);
125 Direction = direction;
126 SourceColumn = sourceColumn;
127 SourceVersion = sourceVersion;
131 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)
132 : this (parameterName, dbType, size, direction, false, precision, scale, sourceColumn, sourceVersion, value)
134 XmlSchemaCollectionDatabase = xmlSchemaCollectionDatabase;
135 XmlSchemaCollectionOwningSchema = xmlSchemaCollectionOwningSchema;
136 XmlSchemaCollectionName = xmlSchemaCollectionName;
137 SourceColumnNullMapping = sourceColumnNullMapping;
141 // This constructor is used internally to construct a
142 // SqlParameter. The value array comes from sp_procedure_params_rowset.
143 // This is in SqlCommand.DeriveParameters.
144 internal SqlParameter (object[] dbValues)
145 : this (dbValues [3].ToString (), String.Empty)
149 Direction = ParameterDirection.Input;
151 ParameterName = (string) dbValues[3];
153 switch ((short) dbValues[5]) {
155 Direction = ParameterDirection.Input;
158 Direction = ParameterDirection.Output;
161 Direction = ParameterDirection.InputOutput;
164 Direction = ParameterDirection.ReturnValue;
167 Direction = ParameterDirection.Input;
170 IsNullable = (dbValues [8] != null &&
171 dbValues [8] != DBNull.Value) ? (bool) dbValues [8] : false;
173 if (dbValues [12] != null && dbValues [12] != DBNull.Value)
174 Precision = (byte) ((short) dbValues [12]);
176 if (dbValues [13] != null && dbValues [13] != DBNull.Value)
177 Scale = (byte) ( (short) dbValues [13]);
179 SetDbTypeName ((string) dbValues [16]);
182 #endregion // Constructors
186 // Used to ensure that only one collection can contain this
188 internal SqlParameterCollection Container {
189 get { return container; }
190 set { container = value; }
193 internal void CheckIfInitialized ()
196 throw new Exception ("all parameters to have an explicity set type");
198 if (MetaParameter.IsVariableSizeType) {
199 if (SqlDbType == SqlDbType.Decimal && Precision == 0)
200 throw new Exception ("Parameter of type 'Decimal' have an explicitly set Precision and Scale");
202 throw new Exception ("all variable length parameters to have an explicitly set non-zero Size");
206 #if ONLY_1_0 || ONLY_1_1
208 [DataSysDescription ("The parameter generic type.")]
209 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
210 [RefreshProperties (RefreshProperties.All)]
211 [DataCategory ("Data")]
218 get { return dbType; }
225 #if ONLY_1_0 || ONLY_1_1
226 [DataCategory ("Data")]
227 [DataSysDescription ("Input, output, or bidirectional parameter.")]
228 [DefaultValue (ParameterDirection.Input)]
231 [RefreshProperties (RefreshProperties.All)]
237 ParameterDirection Direction {
238 get { return direction; }
241 switch( direction ) {
242 case ParameterDirection.Output:
243 MetaParameter.Direction = TdsParameterDirection.Output;
245 case ParameterDirection.InputOutput:
246 MetaParameter.Direction = TdsParameterDirection.InputOutput;
248 case ParameterDirection.ReturnValue:
249 MetaParameter.Direction = TdsParameterDirection.ReturnValue;
255 internal TdsMetaParameter MetaParameter {
256 get { return metaParameter; }
259 #if ONLY_1_0 || ONLY_1_1
261 [DataSysDescription ("a design-time property used for strongly typed code-generation.")]
262 [DefaultValue (false)]
264 [EditorBrowsable (EditorBrowsableState.Advanced)]
271 get { return metaParameter.IsNullable; }
272 set { metaParameter.IsNullable = value; }
276 #if ONLY_1_0 || ONLY_1_1
277 [DataCategory ("Data")]
278 [DataSysDescription ("Offset in variable length data types.")]
282 [EditorBrowsable (EditorBrowsableState.Advanced)]
285 get { return offset; }
286 set { offset = value; }
289 #if ONLY_1_0 || ONLY_1_1
290 [DataSysDescription ("Name of the parameter, like '@p1'")]
297 string ParameterName {
298 get { return metaParameter.ParameterName; }
299 set { metaParameter.ParameterName = value; }
303 #if ONLY_1_0 || ONLY_1_1
304 [DataCategory ("Data")]
305 [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
307 public byte Precision {
308 get { return metaParameter.Precision; }
309 set { metaParameter.Precision = value; }
313 #if ONLY_1_0 || ONLY_1_1
314 [DataCategory ("Data")]
315 [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
318 get { return metaParameter.Scale; }
319 set { metaParameter.Scale = value; }
322 #if ONLY_1_0 || ONLY_1_1
323 [DataCategory ("Data")]
324 [DataSysDescription ("Size of variable length data types (string & arrays).")]
332 get { return metaParameter.Size; }
333 set { metaParameter.Size = value; }
336 #if ONLY_1_0 || ONLY_1_1
337 [DataCategory ("Data")]
338 [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.")]
345 string SourceColumn {
346 get { return sourceColumn; }
347 set { sourceColumn = value; }
350 #if ONLY_1_0 || ONLY_1_1
351 [DataCategory ("Data")]
352 [DataSysDescription ("When used by a DataAdapter.Update (UpdateCommand only), the version of the DataRow value that is used to update the data source.")]
353 [DefaultValue (DataRowVersion.Current)]
359 DataRowVersion SourceVersion {
360 get { return sourceVersion; }
361 set { sourceVersion = value; }
364 #if ONLY_1_0 || ONLY_1_1
365 [DataCategory ("Data")]
366 [DataSysDescription ("The parameter native type.")]
367 [DefaultValue (SqlDbType.NVarChar)]
369 [RefreshProperties (RefreshProperties.All)]
371 [DbProviderSpecificTypeProperty(true)]
373 public SqlDbType SqlDbType {
374 get { return sqlDbType; }
376 SetSqlDbType (value);
381 [TypeConverterAttribute (typeof (StringConverter))]
382 #if ONLY_1_0 || ONLY_1_1
383 [DataCategory ("Data")]
384 [DataSysDescription ("Value of the parameter.")]
385 [DefaultValue (null)]
387 [RefreshProperties (RefreshProperties.All)]
394 get { return metaParameter.Value; }
397 InferSqlType (value);
398 metaParameter.Value = SqlTypeToFrameworkType (value);
404 public SqlCompareOptions CompareInfo{
405 get{ return compareInfo; }
406 set{ compareInfo = value; }
410 public int LocaleId {
411 get { return localeId; }
412 set { localeId = value; }
416 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
417 public Object SqlValue {
418 get { return sqlValue; }
419 set { sqlValue = value; }
422 public override bool SourceColumnNullMapping {
423 get { return sourceColumnNullMapping; }
424 set { sourceColumnNullMapping = value; }
427 public string XmlSchemaCollectionDatabase {
428 get { return xmlSchemaCollectionDatabase; }
429 set { xmlSchemaCollectionDatabase = (value == null ? String.Empty : value); }
432 public string XmlSchemaCollectionName {
433 get { return xmlSchemaCollectionName; }
435 xmlSchemaCollectionName = (value == null ? String.Empty : value);
439 public string XmlSchemaCollectionOwningSchema {
440 get { return xmlSchemaCollectionOwningSchema; }
442 xmlSchemaCollectionOwningSchema = (value == null ? String.Empty : value);
446 #endregion // Properties
450 object ICloneable.Clone ()
452 return new SqlParameter (ParameterName, SqlDbType, Size, Direction, IsNullable, Precision, Scale, SourceColumn, SourceVersion, Value);
455 // If the value is set without the DbType/SqlDbType being set, then we
456 // infer type information.
457 private void InferSqlType (object value)
459 if (value == null || value == DBNull.Value) {
460 SetSqlDbType (SqlDbType.NVarChar);
464 Type type = value.GetType ();
465 string exception = String.Format ("The parameter data type of {0} is invalid.", type.Name);
467 switch (type.FullName) {
469 case "System.Data.SqlTypes.SqlInt64":
470 SetSqlDbType (SqlDbType.BigInt);
472 case "System.Boolean":
473 case "System.Data.SqlTypes.SqlBoolean":
474 SetSqlDbType (SqlDbType.Bit);
476 case "System.String":
477 case "System.Data.SqlTypes.SqlString":
478 SetSqlDbType (SqlDbType.NVarChar);
480 case "System.DateTime":
481 case "System.Data.SqlTypes.SqlDateTime":
482 SetSqlDbType (SqlDbType.DateTime);
484 case "System.Decimal":
485 case "System.Data.SqlTypes.SqlDecimal":
486 SetSqlDbType (SqlDbType.Decimal);
488 case "System.Double":
489 case "System.Data.SqlTypes.SqlDouble":
490 SetSqlDbType (SqlDbType.Float);
492 case "System.Byte[]":
493 case "System.Data.SqlTypes.SqlBinary":
494 SetSqlDbType (SqlDbType.VarBinary);
497 case "System.Data.SqlTypes.SqlByte":
498 SetSqlDbType (SqlDbType.TinyInt);
501 case "System.Data.SqlTypes.SqlInt32":
502 SetSqlDbType (SqlDbType.Int);
504 case "System.Single":
505 case "System.Data.SqlTypes.Single":
506 SetSqlDbType (SqlDbType.Real);
509 case "System.Data.SqlTypes.SqlInt16":
510 SetSqlDbType (SqlDbType.SmallInt);
513 case "System.Data.SqlTypes.SqlGuid":
514 SetSqlDbType (SqlDbType.UniqueIdentifier);
517 case "System.SmallMoney":
518 case "System.Data.SqlTypes.SqlMoney":
519 SetSqlDbType (SqlDbType.Money);
521 case "System.Object":
522 SetSqlDbType (SqlDbType.Variant);
525 throw new ArgumentException (exception);
529 // When the DbType is set, we also set the SqlDbType, as well as the SQL Server
530 // string representation of the type name. If the DbType is not convertible
531 // to an SqlDbType, throw an exception.
532 private void SetDbType (DbType type)
534 string exception = String.Format ("No mapping exists from DbType {0} to a known SqlDbType.", type);
537 case DbType.AnsiString:
538 MetaParameter.TypeName = "varchar";
539 sqlDbType = SqlDbType.VarChar;
540 MetaParameter.IsVariableSizeType = true;
542 case DbType.AnsiStringFixedLength:
543 MetaParameter.TypeName = "char";
544 sqlDbType = SqlDbType.Char;
545 MetaParameter.IsVariableSizeType = true;
548 MetaParameter.TypeName = "varbinary";
549 sqlDbType = SqlDbType.VarBinary;
550 MetaParameter.IsVariableSizeType = true;
553 MetaParameter.TypeName = "bit";
554 sqlDbType = SqlDbType.Bit;
557 MetaParameter.TypeName = "tinyint";
558 sqlDbType = SqlDbType.TinyInt;
560 case DbType.Currency:
561 sqlDbType = SqlDbType.Money;
562 MetaParameter.TypeName = "money";
565 case DbType.DateTime:
566 MetaParameter.TypeName = "datetime";
567 sqlDbType = SqlDbType.DateTime;
570 MetaParameter.TypeName = "decimal";
571 sqlDbType = SqlDbType.Decimal;
574 MetaParameter.TypeName = "float";
575 sqlDbType = SqlDbType.Float;
578 MetaParameter.TypeName = "uniqueidentifier";
579 sqlDbType = SqlDbType.UniqueIdentifier;
582 MetaParameter.TypeName = "smallint";
583 sqlDbType = SqlDbType.SmallInt;
586 MetaParameter.TypeName = "int";
587 sqlDbType = SqlDbType.Int;
590 MetaParameter.TypeName = "bigint";
591 sqlDbType = SqlDbType.BigInt;
594 MetaParameter.TypeName = "sql_variant";
595 sqlDbType = SqlDbType.Variant;
598 MetaParameter.TypeName = "real";
599 sqlDbType = SqlDbType.Real;
602 MetaParameter.TypeName = "nvarchar";
603 sqlDbType = SqlDbType.NVarChar;
604 MetaParameter.IsVariableSizeType = true;
606 case DbType.StringFixedLength:
607 MetaParameter.TypeName = "nchar";
608 sqlDbType = SqlDbType.NChar;
609 MetaParameter.IsVariableSizeType = true;
612 MetaParameter.TypeName = "datetime";
613 sqlDbType = SqlDbType.DateTime;
616 throw new ArgumentException (exception);
621 // Used by internal constructor which has a SQL Server typename
622 private void SetDbTypeName (string dbTypeName)
624 switch (dbTypeName.ToLower ()) {
626 SqlDbType = SqlDbType.BigInt;
629 SqlDbType = SqlDbType.Binary;
632 SqlDbType = SqlDbType.Bit;
635 SqlDbType = SqlDbType.Char;
638 SqlDbType = SqlDbType.DateTime;
641 SqlDbType = SqlDbType.Decimal;
644 SqlDbType = SqlDbType.Float;
647 SqlDbType = SqlDbType.Image;
650 SqlDbType = SqlDbType.Int;
653 SqlDbType = SqlDbType.Money;
656 SqlDbType = SqlDbType.NChar;
659 SqlDbType = SqlDbType.NText;
662 SqlDbType = SqlDbType.NVarChar;
665 SqlDbType = SqlDbType.Real;
667 case "smalldatetime":
668 SqlDbType = SqlDbType.SmallDateTime;
671 SqlDbType = SqlDbType.SmallInt;
674 SqlDbType = SqlDbType.SmallMoney;
677 SqlDbType = SqlDbType.Text;
680 SqlDbType = SqlDbType.Timestamp;
683 SqlDbType = SqlDbType.TinyInt;
685 case "uniqueidentifier":
686 SqlDbType = SqlDbType.UniqueIdentifier;
689 SqlDbType = SqlDbType.VarBinary;
692 SqlDbType = SqlDbType.VarChar;
695 SqlDbType = SqlDbType.Variant;
698 SqlDbType = SqlDbType.Variant;
703 // When the SqlDbType is set, we also set the DbType, as well as the SQL Server
704 // string representation of the type name. If the SqlDbType is not convertible
705 // to a DbType, throw an exception.
706 internal void SetSqlDbType (SqlDbType type)
708 string exception = String.Format ("No mapping exists from SqlDbType {0} to a known DbType.", type);
711 case SqlDbType.BigInt:
712 MetaParameter.TypeName = "bigint";
713 dbType = DbType.Int64;
715 case SqlDbType.Binary:
716 MetaParameter.TypeName = "binary";
717 dbType = DbType.Binary;
718 MetaParameter.IsVariableSizeType = true;
720 case SqlDbType.Timestamp:
721 MetaParameter.TypeName = "timestamp";
722 dbType = DbType.Binary;
724 case SqlDbType.VarBinary:
725 MetaParameter.TypeName = "varbinary";
726 dbType = DbType.Binary;
727 MetaParameter.IsVariableSizeType = true;
730 MetaParameter.TypeName = "bit";
731 dbType = DbType.Boolean;
734 MetaParameter.TypeName = "char";
735 dbType = DbType.AnsiStringFixedLength;
736 MetaParameter.IsVariableSizeType = true;
738 case SqlDbType.DateTime:
739 MetaParameter.TypeName = "datetime";
740 dbType = DbType.DateTime;
742 case SqlDbType.SmallDateTime:
743 MetaParameter.TypeName = "smalldatetime";
744 dbType = DbType.DateTime;
746 case SqlDbType.Decimal:
747 MetaParameter.TypeName = "decimal";
748 dbType = DbType.Decimal;
750 case SqlDbType.Float:
751 MetaParameter.TypeName = "float";
752 dbType = DbType.Double;
754 case SqlDbType.Image:
755 MetaParameter.TypeName = "image";
756 dbType = DbType.Binary;
757 MetaParameter.IsVariableSizeType = true;
760 MetaParameter.TypeName = "int";
761 dbType = DbType.Int32;
763 case SqlDbType.Money:
764 MetaParameter.TypeName = "money";
765 dbType = DbType.Currency;
767 case SqlDbType.SmallMoney:
768 MetaParameter.TypeName = "smallmoney";
769 dbType = DbType.Currency;
771 case SqlDbType.NChar:
772 MetaParameter.TypeName = "nchar";
773 dbType = DbType.StringFixedLength;
774 MetaParameter.IsVariableSizeType = true;
776 case SqlDbType.NText:
777 MetaParameter.TypeName = "ntext";
778 dbType = DbType.String;
779 MetaParameter.IsVariableSizeType = true;
781 case SqlDbType.NVarChar:
782 MetaParameter.TypeName = "nvarchar";
783 dbType = DbType.String;
784 MetaParameter.IsVariableSizeType = true;
787 MetaParameter.TypeName = "real";
788 dbType = DbType.Single;
790 case SqlDbType.SmallInt:
791 MetaParameter.TypeName = "smallint";
792 dbType = DbType.Int16;
795 MetaParameter.TypeName = "text";
796 dbType = DbType.AnsiString;
797 MetaParameter.IsVariableSizeType = true;
799 case SqlDbType.VarChar:
800 MetaParameter.TypeName = "varchar";
801 dbType = DbType.AnsiString;
802 MetaParameter.IsVariableSizeType = true;
804 case SqlDbType.TinyInt:
805 MetaParameter.TypeName = "tinyint";
806 dbType = DbType.Byte;
808 case SqlDbType.UniqueIdentifier:
809 MetaParameter.TypeName = "uniqueidentifier";
810 dbType = DbType.Guid;
812 case SqlDbType.Variant:
813 MetaParameter.TypeName = "sql_variant";
814 dbType = DbType.Object;
817 throw new ArgumentException (exception);
822 public override string ToString()
824 return ParameterName;
827 private object SqlTypeToFrameworkType (object value)
829 if (! (value is INullable)) // if the value is not SqlType
830 return ConvertToFrameworkType (value);
832 // Map to .net type, as Mono TDS respects only types from .net
833 switch (value.GetType ().FullName) {
834 case "System.Data.SqlTypes.SqlBinary":
835 return ( (SqlBinary) value).Value;
836 case "System.Data.SqlTypes.SqlBoolean":
837 return ( (SqlBoolean) value).Value;
838 case "System.Data.SqlTypes.SqlByte":
839 return ( (SqlByte) value).Value;
840 case "System.Data.SqlTypes.SqlDateTime":
841 return ( (SqlDateTime) value).Value;
842 case "System.Data.SqlTypes.SqlDecimal":
843 return ( (SqlDecimal) value).Value;
844 case "System.Data.SqlTypes.SqlDouble":
845 return ( (SqlDouble) value).Value;
846 case "System.Data.SqlTypes.SqlGuid":
847 return ( (SqlGuid) value).Value;
848 case "System.Data.SqlTypes.SqlInt16":
849 return ( (SqlInt16) value).Value;
850 case "System.Data.SqlTypes.SqlInt32 ":
851 return ( (SqlInt32 ) value).Value;
852 case "System.Data.SqlTypes.SqlInt64":
853 return ( (SqlInt64) value).Value;
854 case "System.Data.SqlTypes.SqlMoney":
855 return ( (SqlMoney) value).Value;
856 case "System.Data.SqlTypes.SqlSingle":
857 return ( (SqlSingle) value).Value;
858 case "System.Data.SqlTypes.SqlString":
859 return ( (SqlString) value).Value;
864 internal object ConvertToFrameworkType (object value)
866 if (value == null || value == DBNull.Value)
869 case SqlDbType.BigInt :
870 return Convert.ChangeType (value, typeof (Int64));
871 case SqlDbType.Binary:
872 case SqlDbType.VarBinary:
877 return Convert.ChangeType (value, typeof (bool));
879 return Convert.ChangeType (value, typeof (Int32));
880 case SqlDbType.SmallInt :
881 return Convert.ChangeType (value, typeof (Int16));
882 case SqlDbType.TinyInt :
883 return Convert.ChangeType (value, typeof (byte));
884 case SqlDbType.Float:
885 return Convert.ChangeType (value, typeof (Double));
887 return Convert.ChangeType (value, typeof (Single));
888 case SqlDbType.Decimal:
889 return Convert.ChangeType (value, typeof (Decimal));
890 case SqlDbType.Money:
891 case SqlDbType.SmallMoney:
893 Decimal val = (Decimal)Convert.ChangeType (value, typeof (Decimal));
894 return Decimal.Round(val, 4);
896 case SqlDbType.DateTime:
897 case SqlDbType.SmallDateTime:
898 return Convert.ChangeType (value, typeof (DateTime));
899 case SqlDbType.VarChar:
900 case SqlDbType.NVarChar:
902 case SqlDbType.NChar:
904 case SqlDbType.NText:
905 return Convert.ChangeType (value, typeof (string));
906 case SqlDbType.UniqueIdentifier:
907 return Convert.ChangeType (value, typeof (Guid));
908 case SqlDbType.Variant:
909 return metaParameter.Value;
911 throw new NotImplementedException ("Type Not Supported : " + sqlDbType.ToString());
915 public override void ResetDbType ()
917 InferSqlType (metaParameter.Value);
920 public void ResetSqlDbType ()
922 InferSqlType (metaParameter.Value);
926 #endregion // Methods