Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SqlMetaData Constructor (String, SqlDbType, Int64)

Initializes a new instance of the SqlMetaData class with the specified column name, type, and maximum length.

Namespace:  Microsoft.SqlServer.Server
Assembly:  System.Data (in System.Data.dll)
public SqlMetaData(
	string name,
	SqlDbType dbType,
	long maxLength
)

Parameters

name
Type: System.String

The name of the column.

dbType
Type: System.Data.SqlDbType

The SQL Server type of the parameter or column.

maxLength
Type: System.Int64

The maximum length of the specified type.

ExceptionCondition
ArgumentNullException

The Name is null.

ArgumentException

A SqlDbType that is not allowed was passed to the constructor as dbType.

Only the following are allowed to be passed to the constructor as dbType: Binary, Char, Image, NChar, Ntext, NVarChar, Text, VarBinary, VarChar.

Only a maxLength specification of Max, or -1 is allowed for a dbType of Text, NText, or Image.

For a dbType of Varchar, Nvarchar, or VarBinary, a length specification of Max, or -1, declares the metadata as varchar(max), nvarchar(max), or nvarbinary(max), respectively.

The following are the default values assigned to dbType, depending on the SqlDbType (the XmlSchemaCollectionDatabase, XmlSchemaCollectionName, XmlSchemaCollectionOwningSchema, and Type properties are set to null):

SqlDbType

Precision

Scale

Locale

Compare options

Binary

0

0

0

IgnoreCase, IgnoreKanaType, IgnoreWidth

Char

0

0

<thread>

IgnoreCase, IgnoreKanaType, IgnoreWidth

Image

0

0

0

None

NChar

0

0

<thread>

IgnoreCase, IgnoreKanaType, IgnoreWidth

NText

0

0

<thread>

IgnoreCase, IgnoreKanaType, IgnoreWidth

NVarChar

0

0

<thread>

IgnoreCase, IgnoreKanaType, IgnoreWidth

Text

0

0

<thread>

IgnoreCase, IgnoreKanaType, IgnoreWidth

VarBinary

0

0

IgnoreCase, IgnoreKanaType, IgnoreWidth

VarChar

0

0

<thread>

IgnoreCase, IgnoreKanaType, IgnoreWidth

The following example creates a new SqlMetaData object by specifying the column name, a column data type of SqlDbType.NVarChar, and a maximum length of 12 characters.

public static void CreateSqlMetaData1()
{
   SqlMetaData columnInfo;
   columnInfo = new SqlMetaData("Column1", SqlDbType.NVarChar, 12);
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.