| DateTime | DateTime | NullableDateTime | SqlDateTime | Nullable<DateTime> | Decimal | Decimal | NullableDecimal | SqlDecimal | Nullable<Decimal> | Double | Double | NullableDouble | SqlDouble | Nullable<Double> | Single | Single | NullableSingle | SqlSingle | Nullable<Single> | Guid | Guid | NullableGuid | SqlGuid | Nullable<Guid> | Int16 | Int16 | NullableInt16 | SqlInt16 | Nullable<Int16> | Int32 | Int32 | NullableInt32 | SqlInt32 | Nullable<Int32> | Int64 | Int64 | NullableInt64 | SqlInt64 | Nullable<Int64> | String | String | - | SqlString | - | Time | TimeSpan | - | - | Nullable<TimeSpan> | SByte | SByte | NullableSByte | - | Nullable<SByte>

### Nullable in NHibernateContrib

To use Nullables in NHibernateContrib, add the following file (assemby) references.

- s2container.net/lib/Nullables.dll

Example usage in a source file:

- Import namespace Nullables
- To check if it is a NULL, use the HasValue property
- To retrieve a value, use the Value property

C#

    using System.Text;
    using Nullables;

    namespace Foo
    {
        public class Bar
        {
            private NullableInt64 id;

            public NullableInt64 Id
            {
                get { return id; }
                set { id = value; }
            }

            private NullableBoolean boolType;

            public NullableBoolean BoolType
            {
                get { return boolType; }
                set { boolType = value; }
            }

            public override string ToString()
            {
                StringBuilder buf = new StringBuilder();
                buf.Append(id.HasValue ? id.Value.ToString() : "NULL").Append(", ");
                buf.Append(boolType.HasValue ? boolType.Value.ToString() : "NULL").Append(", ");
                return buf.ToString();
            }
        }
    }

### Null in System.Data.SqlTypes

Example usage in a source file:

- Import namespace System.Data.SqlTypes
- To check if it is a NULL, use the IsNull property
- To retrieve a value, use the Value property

C#

    using System.Data.SqlTypes;
    using System.Text;

    namespace Foo
    {
        public class Bar
        {
            private SqlInt64 id;

            public SqlInt64 Id
            {
                get { return id; }
                set { id = value; }
            }

            private SqlBoolean boolType;

            public SqlBoolean BoolType
            {
                get { return boolType; }
                set { boolType = value; }
            }

            public override string ToString()
            {
                StringBuilder buf = new StringBuilder();
                buf.Append(!id.IsNull ? id.Value.ToString() : "NULL").Append(", ");
                buf.Append(!boolType.IsNull ? boolType.Value.ToString() : "NULL").Append(", ");
                return buf.ToString();
            }
        }
    }

### System.Nullable(.NET 2.0 or higher)

.NET Framework 2.0 or higher supports Nullable datatype.

Example usage in a source file:

- Import namespace System
- To check if the value is a NULL, use the HasValue property
- To retrieve a value, use the Value property

C#

    using System;
    using System.Text;

    namespace Foo
    {
        public class Bar
        {
            private Nullable<Int64> id;

            public Nullable<Int64> Id
            {
                get { return id; }
                set { id = value; }
            }

            private Nullable<Boolean> boolType;

            public Nullable<Boolean> BoolType
            {
                get { return boolType; }
                set { boolType = value; }
            }

            public override string ToString()
            {
                StringBuilder buf = new StringBuilder();
                buf.Append(id.HasValue ? id.Value.ToString() : "NULL").Append(", ");
                buf.Append(boolType.HasValue ? boolType.Value.ToString() : "NULL").Append(", ");
                return buf.ToString();
            }
        }
    }

## Parameter Marker(@, :, ?)

Parameter markers that may be used in a SQL command depends on the ADO.NET data provider. As an example, SqlClient uses "@parmname", OracleClient uses ":parmname", OleDb uses "?", and Odbc uses "?".

S2ADO allows SQL commands to be independent of data provider by changing parameter markers depending on a data provider used.

Following is an example:

Data Provider | SQL command
--- | ---
(User's SQL command) | SELECT * FROM emp WHERE empno = @empno OR empno = :empno OR empno = ?
SqlClient | SELECT * FROM emp WHERE empno = @0 OR empno = @1 OR empno = @2
OracleClient | SELECT * FROM emp WHERE empno = :0 OR empno = :1 OR empno = :2
OleDb | SELECT * FROM emp WHERE empno = ? OR empno = ? OR empno = ?
Odbc | SELECT * FROM emp WHERE empno = ? OR empno = ? OR empno = ?

Note: Several types of parameter markers may be used in a SQL command but for readability, it is recommended to use one type.

Trans. by H.Ozawa | Copyright© 2004-2007, The Seasar Foundation and the others. All rights reserved.