asp.net.ph

SqlParameter Class

System.Data.SqlClient Namespace


Represents a parameter to an SqlCommand, and optionally, its mapping to DataSet columns.

SqlParameter Class Members

Collapse   Constructors

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 )

Collapse   Properties

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 ]

Collapse   Methods

Visibility Name Parameters Return Type
public ResetDbType ( ) Void
public ResetSqlDbType ( ) Void
public ToString ( ) String

Remarks

Parameter names are not case sensitive.

Example

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 ( );
  C# VB

 Show me 

See Also

SqlParameterCollection   SqlCommand   Updating Data at the Database Level Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph