Fixed Bug 74948 - SqlParameter also takes DBNull Value.
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlParameter.cs
1 //
2 // System.Data.SqlClient.SqlParameter.cs
3 //
4 // Author:
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 //
11 // (C) Ximian, Inc. 2002
12 // Copyright (C) Tim Coleman, 2002
13 //
14
15 //
16 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
17 //
18 // Permission is hereby granted, free of charge, to any person obtaining
19 // a copy of this software and associated documentation files (the
20 // "Software"), to deal in the Software without restriction, including
21 // without limitation the rights to use, copy, modify, merge, publish,
22 // distribute, sublicense, and/or sell copies of the Software, and to
23 // permit persons to whom the Software is furnished to do so, subject to
24 // the following conditions:
25 // 
26 // The above copyright notice and this permission notice shall be
27 // included in all copies or substantial portions of the Software.
28 // 
29 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 //
37
38 using Mono.Data.Tds;
39 using Mono.Data.Tds.Protocol;
40 using System;
41 using System.ComponentModel;
42 using System.Data;
43 using System.Data.Common;
44 #if NET_2_0
45 using System.Data.ProviderBase;
46 using System.Data.SqlTypes;
47 #endif // NET_2_0
48 using System.Runtime.InteropServices;
49 using System.Text;
50
51 namespace System.Data.SqlClient {
52         [TypeConverterAttribute (typeof (SqlParameterConverter))]
53 #if NET_2_0
54         public sealed class SqlParameter : DbParameterBase, IDbDataParameter, IDataParameter, ICloneable
55 #else
56         public sealed class SqlParameter : MarshalByRefObject, IDbDataParameter, IDataParameter, ICloneable
57 #endif // NET_2_0
58         {
59                 #region Fields
60
61                 TdsMetaParameter metaParameter;
62
63                 SqlParameterCollection container = null;
64                 DbType dbType;
65                 ParameterDirection direction = ParameterDirection.Input;
66                 bool isNullable;
67                 bool isSizeSet = false;
68                 bool isTypeSet = false;
69                 int offset;
70                 SqlDbType sqlDbType;
71                 string sourceColumn;
72                 DataRowVersion sourceVersion;
73
74                 #endregion // Fields
75
76                 #region Constructors
77
78                 public SqlParameter () 
79                         : this (String.Empty, SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
80                 {
81                 }
82
83                 public SqlParameter (string parameterName, object value) 
84                 {
85                         metaParameter = new TdsMetaParameter (parameterName, value);
86                         this.sourceVersion = DataRowVersion.Current;
87                         InferSqlType (value);
88                 }
89                 
90                 public SqlParameter (string parameterName, SqlDbType dbType) 
91                         : this (parameterName, dbType, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
92                 {
93                 }
94
95                 public SqlParameter (string parameterName, SqlDbType dbType, int size) 
96                         : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null)
97                 {
98                 }
99                 
100                 public SqlParameter (string parameterName, SqlDbType dbType, int size, string sourceColumn) 
101                         : this (parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, sourceColumn, DataRowVersion.Current, null)
102                 {
103                 }
104                 
105                 [EditorBrowsable (EditorBrowsableState.Advanced)]        
106                 public SqlParameter (string parameterName, SqlDbType dbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value) 
107                 {
108                         metaParameter = new TdsMetaParameter (parameterName, size, isNullable, precision, scale, value);
109
110                         SqlDbType = dbType;
111                         Direction = direction;
112                         SourceColumn = sourceColumn;
113                         SourceVersion = sourceVersion;
114                 }
115
116                 // This constructor is used internally to construct a
117                 // SqlParameter.  The value array comes from sp_procedure_params_rowset.
118                 // This is in SqlCommand.DeriveParameters.
119                 internal SqlParameter (object[] dbValues) 
120                         : this (dbValues [3].ToString (), String.Empty)
121                 {
122                         Precision = 0;
123                         Scale = 0;
124                         Direction = ParameterDirection.Input;
125
126                         ParameterName = (string) dbValues[3];
127
128                         switch ((short) dbValues[5]) {
129                         case 1:
130                                 Direction = ParameterDirection.Input;
131                                 break;
132                         case 2:
133                                 Direction = ParameterDirection.Output;
134                                 break;
135                         case 3:
136                                 Direction = ParameterDirection.InputOutput;
137                                 break;
138                         case 4:
139                                 Direction = ParameterDirection.ReturnValue;
140                                 break;
141                         default:
142                                 Direction = ParameterDirection.Input;
143                                 break;
144                         }
145                         IsNullable = (dbValues [8] != null && 
146                                       dbValues [8] != DBNull.Value) ? (bool) dbValues [8] : false;
147
148                         if (dbValues [12] != null && dbValues [12] != DBNull.Value)
149                                 Precision = (byte) ((short) dbValues [12]);
150
151                         if (dbValues [13] != null && dbValues [13] != DBNull.Value)
152                                 Scale = (byte) ( (short) dbValues [13]);
153
154                         SetDbTypeName ((string) dbValues [16]);
155                 }
156
157                 #endregion // Constructors
158
159                 #region Properties
160
161                 // Used to ensure that only one collection can contain this
162                 // parameter
163                 internal SqlParameterCollection Container {
164                         get { return container; }
165                         set { container = value; }
166                 }
167
168 #if NET_1_1     
169                 [Browsable (false)]
170                 [DataSysDescription ("The parameter generic type.")]
171                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
172                 [RefreshProperties (RefreshProperties.All)]
173 #endif                                                   
174                 [DataCategory ("Data")]
175                 public 
176 #if NET_2_0
177                 override
178 #endif // NET_2_0
179          DbType DbType {
180                         get { return dbType; }
181                         set { 
182                                 SetDbType (value); 
183                                 isTypeSet = true;
184                         }
185                 }
186
187                 [DataCategory ("Data")]
188 #if NET_1_1
189                 [DataSysDescription ("Input, output, or bidirectional parameter.")]
190                 [DefaultValue (ParameterDirection.Input)]
191 #endif
192 #if NET_2_0
193                 [RefreshProperties (RefreshProperties.All)]
194 #endif
195                 public 
196 #if NET_2_0
197                 override
198 #endif // NET_2_0
199          ParameterDirection Direction {
200                         get { return direction; }
201                         set { 
202                                 direction = value; 
203                                 switch( direction ) {
204                                         case ParameterDirection.Output:
205                                         MetaParameter.Direction = TdsParameterDirection.Output;
206                                                 break;
207                                         case ParameterDirection.InputOutput:
208                                                 MetaParameter.Direction = TdsParameterDirection.InputOutput;
209                                                 break;
210                                         case ParameterDirection.ReturnValue:
211                                                 MetaParameter.Direction = TdsParameterDirection.ReturnValue;
212                                                 break;
213                                 }
214                         }
215                 }
216
217                 internal TdsMetaParameter MetaParameter {
218                         get { return metaParameter; }
219                 }
220
221                 string IDataParameter.ParameterName {
222                         get { return metaParameter.ParameterName; }
223                         set { metaParameter.ParameterName = value; }
224                 }
225
226 #if NET_1_1
227                 [Browsable (false)]
228                 [DataSysDescription ("a design-time property used for strongly typed code-generation.")]
229                 [DefaultValue (false)]
230                 [DesignOnly (true)]
231                 [EditorBrowsable (EditorBrowsableState.Advanced)]        
232 #endif
233                 public 
234 #if NET_2_0
235                 override
236 #endif // NET_2_0
237          bool IsNullable        {
238                         get { return metaParameter.IsNullable; }
239                         set { metaParameter.IsNullable = value; }
240                 }
241
242                 [Browsable (false)]
243                 [DataCategory ("Data")]
244 #if NET_1_1
245                 [DataSysDescription ("Offset in variable length data types.")]
246                 [DefaultValue (0)]
247 #endif
248 #if NET_2_0
249                 [EditorBrowsable (EditorBrowsableState.Advanced)]
250 #endif
251                 public 
252 #if NET_2_0
253                 override
254 #endif // NET_2_0
255          int Offset {
256                         get { return offset; }
257                         set { offset = value; }
258                 }
259         
260 #if NET_1_1     
261                 [DataSysDescription ("Name of the parameter, like '@p1'")]
262                 [DefaultValue ("")]
263 #endif
264                 public 
265 #if NET_2_0
266                 override
267 #endif // NET_2_0
268          string ParameterName {
269                         get { return metaParameter.ParameterName; }
270                         set { metaParameter.ParameterName = value; }
271                 }
272
273                 [DataCategory ("Data")]
274 #if NET_1_1
275                 [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
276                 [DefaultValue (0)]
277 #endif
278 #if NET_2_0
279                 [Browsable (false)]
280                 [EditorBrowsable (EditorBrowsableState.Never)]
281 #endif          
282                 public 
283 #if NET_2_0
284                 override
285 #endif // NET_2_0
286          byte Precision {
287                         get { return metaParameter.Precision; }
288                         set { metaParameter.Precision = value; }
289                 }
290
291                 [DataCategory ("Data")]
292 #if NET_1_1
293                 [DataSysDescription ("For decimal, numeric, varnumeric DBTypes.")]
294                 [DefaultValue (0)]
295 #endif
296 #if NET_2_0
297                 [Browsable (false)]
298                 [EditorBrowsable (EditorBrowsableState.Never)]
299 #endif
300                 public 
301 #if NET_2_0
302                 override
303 #endif // NET_2_0
304          byte Scale {
305                         get { return metaParameter.Scale; }
306                         set { metaParameter.Scale = value; }
307                 }
308
309                 [DataCategory ("Data")]
310 #if NET_1_1
311                 [DataSysDescription ("Size of variable length data types (strings & arrays).")]
312                 [DefaultValue (0)]
313 #endif
314                 public 
315 #if NET_2_0
316                 override
317 #endif // NET_2_0
318          int Size {
319                         get { return metaParameter.Size; }
320                         set { metaParameter.Size = value; }
321                 }
322
323                 [DataCategory ("Data")]
324 #if NET_1_1
325                 [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.")]
326                 [DefaultValue ("")]
327 #endif
328                 public 
329 #if NET_2_0
330                 override
331 #endif // NET_2_0
332          string SourceColumn {
333                         get { return sourceColumn; }
334                         set { sourceColumn = value; }
335                 }
336
337                 [DataCategory ("Data")]
338 #if NET_1_1
339                 [DataSysDescription ("When used by a DataAdapter.Update (UpdateCommand only), the version of the DataRow value that is used to update the data source.")]
340                 [DefaultValue (DataRowVersion.Current)]
341 #endif
342                 public 
343 #if NET_2_0
344                 override
345 #endif // NET_2_0
346          DataRowVersion SourceVersion {
347                         get { return sourceVersion; }
348                         set { sourceVersion = value; }
349                 }
350                 
351                 [DataCategory ("Data")]
352 #if NET_1_1
353                 [DataSysDescription ("The parameter native type.")]
354                 [DefaultValue (SqlDbType.NVarChar)]
355 #endif
356                 [RefreshProperties (RefreshProperties.All)]
357 #if NET_2_0
358                 [DbProviderSpecificTypeProperty(true)]
359 #endif
360                 public SqlDbType SqlDbType {
361                         get { return sqlDbType; }
362                         set { 
363                                 SetSqlDbType (value); 
364                                 isTypeSet = true;
365                         }
366                 }
367
368                 [DataCategory ("Data")]
369 #if NET_1_1
370                 [DataSysDescription ("Value of the parameter.")]
371                 [DefaultValue (null)]
372 #endif
373                 [TypeConverterAttribute (typeof (StringConverter))]
374 #if NET_2_0
375                 [RefreshProperties (RefreshProperties.All)]             
376 #endif
377                 public 
378 #if NET_2_0
379                 override
380 #endif // NET_2_0
381          object Value {
382                         get { return metaParameter.Value; }
383                         set { 
384                                 if (!isTypeSet)
385                                         InferSqlType (value);
386                                 metaParameter.Value = value; 
387                         }
388                 }
389
390 #if NET_2_0
391 //              public SqlCompareOptions CompareInfo{
392
393 #endif
394
395                 #endregion // Properties
396
397                 #region Methods
398
399                 object ICloneable.Clone ()
400                 {
401                         return new SqlParameter (ParameterName, SqlDbType, Size, Direction, IsNullable, Precision, Scale, SourceColumn, SourceVersion, Value);
402                 }
403
404                 // If the value is set without the DbType/SqlDbType being set, then we
405                 // infer type information.
406                 private void InferSqlType (object value)
407                 {
408                         Type type = value.GetType ();
409
410                         string exception = String.Format ("The parameter data type of {0} is invalid.", type.Name);
411
412                         switch (type.FullName) {
413                         case "System.Int64":
414                                 SetSqlDbType (SqlDbType.BigInt);
415                                 break;
416                         case "System.Boolean":
417                                 SetSqlDbType (SqlDbType.Bit);
418                                 break;
419                         case "System.String":
420                                 SetSqlDbType (SqlDbType.NVarChar);
421                                 break;
422                         case "System.DateTime":
423                                 SetSqlDbType (SqlDbType.DateTime);
424                                 break;
425                         case "System.Decimal":
426                                 SetSqlDbType (SqlDbType.Decimal);
427                                 break;
428                         case "System.Double":
429                                 SetSqlDbType (SqlDbType.Float);
430                                 break;
431                         case "System.Byte[]":
432                                 SetSqlDbType (SqlDbType.VarBinary);
433                                 break;
434                         case "System.Byte":
435                                 SetSqlDbType (SqlDbType.TinyInt);
436                                 break;
437                         case "System.Int32":
438                                 SetSqlDbType (SqlDbType.Int);
439                                 break;
440                         case "System.Single":
441                                 SetSqlDbType (SqlDbType.Real);
442                                 break;
443                         case "System.Int16":
444                                 SetSqlDbType (SqlDbType.SmallInt);
445                                 break;
446                         case "System.Guid":
447                                 SetSqlDbType (SqlDbType.UniqueIdentifier);
448                                 break;
449                         case "System.Object":
450                                 SetSqlDbType (SqlDbType.Variant);
451                                 break;
452                         case "System.DBNull":
453                                 SetSqlDbType(SqlDbType.Variant); // variant can contain numeric,
454                                                                 //string,binary or data and also nul                                                                //values, so we can later resolve                                                                   // it to correct type.  
455                                 break;  
456                         default:
457                                 throw new ArgumentException (exception);                                
458                         }
459                 }
460
461                 // When the DbType is set, we also set the SqlDbType, as well as the SQL Server
462                 // string representation of the type name.  If the DbType is not convertible
463                 // to an SqlDbType, throw an exception.
464                 private void SetDbType (DbType type)
465                 {
466                         string exception = String.Format ("No mapping exists from DbType {0} to a known SqlDbType.", type);
467
468                         switch (type) {
469                         case DbType.AnsiString:
470                                 MetaParameter.TypeName = "varchar";
471                                 sqlDbType = SqlDbType.VarChar;
472                                 break;
473                         case DbType.AnsiStringFixedLength:
474                                 MetaParameter.TypeName = "char";
475                                 sqlDbType = SqlDbType.Char;
476                                 break;
477                         case DbType.Binary:
478                                 MetaParameter.TypeName = "varbinary";
479                                 sqlDbType = SqlDbType.VarBinary;
480                                 break;
481                         case DbType.Boolean:
482                                 MetaParameter.TypeName = "bit";
483                                 sqlDbType = SqlDbType.Bit;
484                                 break;
485                         case DbType.Byte:
486                                 MetaParameter.TypeName = "tinyint";
487                                 sqlDbType = SqlDbType.TinyInt;
488                                 break;
489                         case DbType.Currency:
490                                 sqlDbType = SqlDbType.Money;
491                                 MetaParameter.TypeName = "money";
492                                 break;
493                         case DbType.Date:
494                         case DbType.DateTime:
495                                 MetaParameter.TypeName = "datetime";
496                                 sqlDbType = SqlDbType.DateTime;
497                                 break;
498                         case DbType.Decimal:
499                                 MetaParameter.TypeName = "decimal";
500                                 sqlDbType = SqlDbType.Decimal;
501                                 break;
502                         case DbType.Double:
503                                 MetaParameter.TypeName = "float";
504                                 sqlDbType = SqlDbType.Float;
505                                 break;
506                         case DbType.Guid:
507                                 MetaParameter.TypeName = "uniqueidentifier";
508                                 sqlDbType = SqlDbType.UniqueIdentifier;
509                                 break;
510                         case DbType.Int16:
511                                 MetaParameter.TypeName = "smallint";
512                                 sqlDbType = SqlDbType.SmallInt;
513                                 break;
514                         case DbType.Int32:
515                                 MetaParameter.TypeName = "int";
516                                 sqlDbType = SqlDbType.Int;
517                                 break;
518                         case DbType.Int64:
519                                 MetaParameter.TypeName = "bigint";
520                                 sqlDbType = SqlDbType.BigInt;
521                                 break;
522                         case DbType.Object:
523                                 MetaParameter.TypeName = "sql_variant";
524                                 sqlDbType = SqlDbType.Variant;
525                                 break;
526                         case DbType.Single:
527                                 MetaParameter.TypeName = "real";
528                                 sqlDbType = SqlDbType.Real;
529                                 break;
530                         case DbType.String:
531                                 MetaParameter.TypeName = "nvarchar";
532                                 sqlDbType = SqlDbType.NVarChar;
533                                 break;
534                         case DbType.StringFixedLength:
535                                 MetaParameter.TypeName = "nchar";
536                                 sqlDbType = SqlDbType.NChar;
537                                 break;
538                         case DbType.Time:
539                                 MetaParameter.TypeName = "datetime";
540                                 sqlDbType = SqlDbType.DateTime;
541                                 break;
542                         default:
543                                 throw new ArgumentException (exception);
544                         }
545                         dbType = type;
546                 }
547
548                 // Used by internal constructor which has a SQL Server typename
549                 private void SetDbTypeName (string dbTypeName)
550                 {
551                         switch (dbTypeName.ToLower ()) {        
552                         case "bigint":
553                                 SqlDbType = SqlDbType.BigInt;
554                                 break;
555                         case "binary":
556                                 SqlDbType = SqlDbType.Binary;
557                                 break;
558                         case "bit":
559                                 SqlDbType = SqlDbType.Bit;
560                                 break;
561                         case "char":
562                                 SqlDbType = SqlDbType.Char;
563                                 break;
564                         case "datetime":
565                                 SqlDbType = SqlDbType.DateTime;
566                                 break;
567                         case "decimal":
568                                 SqlDbType = SqlDbType.Decimal;
569                                 break;
570                         case "float":
571                                 SqlDbType = SqlDbType.Float;
572                                 break;
573                         case "image":
574                                 SqlDbType = SqlDbType.Image;
575                                 break;
576                         case "int":
577                                 SqlDbType = SqlDbType.Int;
578                                 break;
579                         case "money":
580                                 SqlDbType = SqlDbType.Money;
581                                 break;
582                         case "nchar":
583                                 SqlDbType = SqlDbType.NChar;
584                                 break;
585                         case "ntext":
586                                 SqlDbType = SqlDbType.NText;
587                                 break;
588                         case "nvarchar":
589                                 SqlDbType = SqlDbType.NVarChar;
590                                 break;
591                         case "real":
592                                 SqlDbType = SqlDbType.Real;
593                                 break;
594                         case "smalldatetime":
595                                 SqlDbType = SqlDbType.SmallDateTime;
596                                 break;
597                         case "smallint":
598                                 SqlDbType = SqlDbType.SmallInt;
599                                 break;
600                         case "smallmoney":
601                                 SqlDbType = SqlDbType.SmallMoney;
602                                 break;
603                         case "text":
604                                 SqlDbType = SqlDbType.Text;
605                                 break;
606                         case "timestamp":
607                                 SqlDbType = SqlDbType.Timestamp;
608                                 break;
609                         case "tinyint":
610                                 SqlDbType = SqlDbType.TinyInt;
611                                 break;
612                         case "uniqueidentifier":
613                                 SqlDbType = SqlDbType.UniqueIdentifier;
614                                 break;
615                         case "varbinary":
616                                 SqlDbType = SqlDbType.VarBinary;
617                                 break;
618                         case "varchar":
619                                 SqlDbType = SqlDbType.VarChar;
620                                 break;
621                         default:
622                                 SqlDbType = SqlDbType.Variant;
623                                 break;
624                         }
625                 }
626
627                 // When the SqlDbType is set, we also set the DbType, as well as the SQL Server
628                 // string representation of the type name.  If the SqlDbType is not convertible
629                 // to a DbType, throw an exception.
630                 private void SetSqlDbType (SqlDbType type)
631                 {
632                         string exception = String.Format ("No mapping exists from SqlDbType {0} to a known DbType.", type);
633
634                         switch (type) {
635                         case SqlDbType.BigInt:
636                                 MetaParameter.TypeName = "bigint";
637                                 dbType = DbType.Int64;
638                                 break;
639                         case SqlDbType.Binary:
640                                 MetaParameter.TypeName = "binary";
641                                 dbType = DbType.Binary;
642                                 break;
643                         case SqlDbType.Timestamp:
644                                 MetaParameter.TypeName = "timestamp";
645                                 dbType = DbType.Binary;
646                                 break;
647                         case SqlDbType.VarBinary:
648                                 MetaParameter.TypeName = "varbinary";
649                                 dbType = DbType.Binary;
650                                 break;
651                         case SqlDbType.Bit:
652                                 MetaParameter.TypeName = "bit";
653                                 dbType = DbType.Boolean;
654                                 break;
655                         case SqlDbType.Char:
656                                 MetaParameter.TypeName = "char";
657                                 dbType = DbType.AnsiStringFixedLength;
658                                 break;
659                         case SqlDbType.DateTime:
660                                 MetaParameter.TypeName = "datetime";
661                                 dbType = DbType.DateTime;
662                                 break;
663                         case SqlDbType.SmallDateTime:
664                                 MetaParameter.TypeName = "smalldatetime";
665                                 dbType = DbType.DateTime;
666                                 break;
667                         case SqlDbType.Decimal:
668                                 MetaParameter.TypeName = "decimal";
669                                 dbType = DbType.Decimal;
670                                 break;
671                         case SqlDbType.Float:
672                                 MetaParameter.TypeName = "float";
673                                 dbType = DbType.Double;
674                                 break;
675                         case SqlDbType.Image:
676                                 MetaParameter.TypeName = "image";
677                                 dbType = DbType.Binary;
678                                 break;
679                         case SqlDbType.Int:
680                                 MetaParameter.TypeName = "int";
681                                 dbType = DbType.Int32;
682                                 break;
683                         case SqlDbType.Money:
684                                 MetaParameter.TypeName = "money";
685                                 dbType = DbType.Currency;
686                                 break;
687                         case SqlDbType.SmallMoney:
688                                 MetaParameter.TypeName = "smallmoney";
689                                 dbType = DbType.Currency;
690                                 break;
691                         case SqlDbType.NChar:
692                                 MetaParameter.TypeName = "nchar";
693                                 dbType = DbType.StringFixedLength;
694                                 break;
695                         case SqlDbType.NText:
696                                 MetaParameter.TypeName = "ntext";
697                                 dbType = DbType.String;
698                                 break;
699                         case SqlDbType.NVarChar:
700                                 MetaParameter.TypeName = "nvarchar";
701                                 dbType = DbType.String;
702                                 break;
703                         case SqlDbType.Real:
704                                 MetaParameter.TypeName = "real";
705                                 dbType = DbType.Single;
706                                 break;
707                         case SqlDbType.SmallInt:
708                                 MetaParameter.TypeName = "smallint";
709                                 dbType = DbType.Int16;
710                                 break;
711                         case SqlDbType.Text:
712                                 MetaParameter.TypeName = "text";
713                                 dbType = DbType.AnsiString;
714                                 break;
715                         case SqlDbType.VarChar:
716                                 MetaParameter.TypeName = "varchar";
717                                 dbType = DbType.AnsiString;
718                                 break;
719                         case SqlDbType.TinyInt:
720                                 MetaParameter.TypeName = "tinyint";
721                                 dbType = DbType.Byte;
722                                 break;
723                         case SqlDbType.UniqueIdentifier:
724                                 MetaParameter.TypeName = "uniqueidentifier";
725                                 dbType = DbType.Guid;
726                                 break;
727                         case SqlDbType.Variant:
728                                 MetaParameter.TypeName = "sql_variant";
729                                 dbType = DbType.Object;
730                                 break;
731                         default:
732                                 throw new ArgumentException (exception);
733                         }
734                         sqlDbType = type;
735                 }
736
737                 public override string ToString() 
738                 {
739                         return ParameterName;
740                 }
741
742 #if NET_2_0
743                 [MonoTODO]
744                 public override void CopyTo (DbParameter param)
745                 {
746                         throw new NotImplementedException ();
747                 }
748                 
749                 [MonoTODO]
750                 public override void ResetDbType ()
751                 {
752                         throw new NotImplementedException ();
753                 }
754 #endif // NET_2_0
755
756                 #endregion // Methods
757         }
758 }