System.Data.SqlClient Namespace
Represents a parameter to an SqlCommand, and optionally, its mapping to DataSet columns.
Visibility |
Constructor |
Parameters |
public |
SqlParameter |
( )
|
public |
SqlParameter |
(
String
parameterName
,
SqlDbType
dbType
,
Int32
size
,
ParameterDirection
direction
,
Boolean
isNullable
,
Byte
precision
,
Byte
scale
,
String
sourceColumn
,
DataRowVersion
sourceVersion
,
Object
value
)
|
public |
SqlParameter |
(
String
parameterName
,
SqlDbType
dbType
,
Int32
size
,
ParameterDirection
direction
,
Byte
precision
,
Byte
scale
,
String
sourceColumn
,
DataRowVersion
sourceVersion
,
Boolean
sourceColumnNullMapping
,
Object
value
,
String
xmlSchemaCollectionDatabase
,
String
xmlSchemaCollectionOwningSchema
,
String
xmlSchemaCollectionName
)
|
public |
SqlParameter |
(
String
parameterName
,
SqlDbType
dbType
)
|
public |
SqlParameter |
(
String
parameterName
,
Object
value
)
|
public |
SqlParameter |
(
String
parameterName
,
SqlDbType
dbType
,
Int32
size
)
|
public |
SqlParameter |
(
String
parameterName
,
SqlDbType
dbType
,
Int32
size
,
String
sourceColumn
)
|
Visibility |
Name |
Value Type |
Accessibility |
public |
CompareInfo
|
SqlCompareOptions |
[ Get , Set ] |
public |
DbType
|
DbType |
[ Get , Set ] |
public |
Direction
|
ParameterDirection |
[ Get , Set ] |
public |
ForceColumnEncryption
|
Boolean |
[ Get , Set ] |
public |
IsNullable
|
Boolean |
[ Get , Set ] |
public |
LocaleId
|
Int32 |
[ Get , Set ] |
public |
Offset
|
Int32 |
[ Get , Set ] |
public |
ParameterName
|
String |
[ Get , Set ] |
public |
Precision
|
Byte |
[ Get , Set ] |
public |
Scale
|
Byte |
[ Get , Set ] |
public |
Size
|
Int32 |
[ Get , Set ] |
public |
SourceColumn
|
String |
[ Get , Set ] |
public |
SourceColumnNullMapping
|
Boolean |
[ Get , Set ] |
public |
SourceVersion
|
DataRowVersion |
[ Get , Set ] |
public |
SqlDbType
|
SqlDbType |
[ Get , Set ] |
public |
SqlValue
|
Object |
[ Get , Set ] |
public |
TypeName
|
String |
[ Get , Set ] |
public |
UdtTypeName
|
String |
[ Get , Set ] |
public |
Value
|
Object |
[ Get , Set ] |
public |
XmlSchemaCollectionDatabase
|
String |
[ Get , Set ] |
public |
XmlSchemaCollectionName
|
String |
[ Get , Set ] |
public |
XmlSchemaCollectionOwningSchema
|
String |
[ Get , Set ] |
|
Parameter names are not case sensitive.
The following example shows how to initialize multiple instances of the SqlParameter class that are here used to populate the values of an SQL Insert command. These parameters are used to gather data from user input for insertion into an SQL Server™ data store.
// define insert command parameters
myCmd.CommandText = "INSERT INTO aspx_messages " +
" ( MessageDate, MessageFrom, Email, MessageSubject, MessageBody ) " +
"VALUES ( @Date, @From, @Mail, @Subject, @Body ) " +
"SET @Identity = @@Identity";
myCmd.Parameters.Add ( "@Date", SqlDbType.SmallDateTime );
myCmd.Parameters [ "@Date" ].Value = DateTime.Now.ToString ( );
myCmd.Parameters.Add ( "@From", SqlDbType.NVarChar );
myCmd.Parameters [ "@From" ].Value = msgFrom.Value;
myCmd.Parameters.Add ( "@Mail", SqlDbType.NVarChar );
myCmd.Parameters [ "@Mail" ].Value = msgEmail.Value;
myCmd.Parameters.Add ( "@Subject", SqlDbType.NVarChar );
myCmd.Parameters [ "@Subject" ].Value = msgSubject.Value;
myCmd.Parameters.Add ( "@Body", SqlDbType.NText );
myCmd.Parameters [ "@Body" ].Value = msgBody.Value;
// used for getting new record ID
myCmd.Parameters.Add ( "@Identity", SqlDbType.Int );
myCmd.Parameters [ "@Identity" ].Direction = ParameterDirection.Output;
myCmd.Connection.Open ( );
myCmd.ExecuteNonQuery ( );
myCmd.Connection.Close ( );
' define insert command parameters
myCmd.CommandText = "INSERT INTO aspx_messages " +
" ( MessageDate, MessageFrom, Email, MessageSubject, MessageBody ) " +
"VALUES ( @Date, @From, @Mail, @Subject, @Body ) " +
"SET @Identity = @@Identity"
myCmd.Parameters.Add ( "@Date", SqlDbType.SmallDateTime )
myCmd.Parameters [ "@Date" ].Value = DateTime.Now.ToString ( )
myCmd.Parameters.Add ( "@From", SqlDbType.NVarChar )
myCmd.Parameters [ "@From" ].Value = msgFrom.Value
myCmd.Parameters.Add ( "@Mail", SqlDbType.NVarChar )
myCmd.Parameters [ "@Mail" ].Value = msgEmail.Value
myCmd.Parameters.Add ( "@Subject", SqlDbType.NVarChar )
myCmd.Parameters [ "@Subject" ].Value = msgSubject.Value
myCmd.Parameters.Add ( "@Body", SqlDbType.NText )
myCmd.Parameters [ "@Body" ].Value = msgBody.Value
' used for getting new record ID
myCmd.Parameters.Add ( "@Identity", SqlDbType.Int )
myCmd.Parameters [ "@Identity" ].Direction = ParameterDirection.Output
myCmd.Connection.Open ( )
myCmd.ExecuteNonQuery ( )
myCmd.Connection.Close ( ) |
|
C# |
VB |
Show me
SqlParameterCollection SqlCommand Updating Data at the Database Level
|
|