This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Download Microsoft Edge
More info about Internet Explorer and Microsoft Edge
public ref class SqlParameter sealed : System::Data::Common::DbParameter, ICloneable
[System.ComponentModel.TypeConverter(typeof(Microsoft.Data.SqlClient.SqlParameter+SqlParameterConverter))]
public sealed class SqlParameter : System.Data.Common.DbParameter, ICloneable
public sealed class SqlParameter : System.Data.Common.DbParameter, ICloneable
[<System.ComponentModel.TypeConverter(typeof(Microsoft.Data.SqlClient.SqlParameter+SqlParameterConverter))>]
type SqlParameter = class
inherit DbParameter
interface IDbDataParameter
interface IDataParameter
interface ICloneable
type SqlParameter = class
inherit DbParameter
interface IDataParameter
interface IDbDataParameter
interface ICloneable
Public NotInheritable Class SqlParameter
Inherits DbParameter
Implements ICloneable
Inheritance
SqlParameter
Examples
The following example creates multiple instances of
SqlParameter
through the
SqlParameterCollection
collection within the
SqlDataAdapter
. These parameters are used to select data from the data source and put the data in the
DataSet
. This example assumes that a
DataSet
and a
SqlDataAdapter
have already been created by using the appropriate schema, commands, and connection. For more information and additional examples on using parameters, see
Retrieving and Modifying Data in ADO.NET
and
Configuring parameters
.
using Microsoft.Data.SqlClient;
using System.Xml;
using System.Data.Common;
using System.Windows.Forms;
public class Form1 : Form
protected DataSet categoriesDataSet;
protected DataGrid dataGrid1;
protected SqlDataAdapter categoriesAdapter;
public void AddSqlParameters()
// ...
// create categoriesDataSet and categoriesAdapter
// ...
categoriesAdapter.SelectCommand.Parameters.Add(
"@CategoryName", SqlDbType.VarChar, 80).Value = "toasters";
categoriesAdapter.SelectCommand.Parameters.Add(
"@SerialNum", SqlDbType.Int).Value = 239;
categoriesAdapter.Fill(categoriesDataSet);
Parameter names are not case sensitive.
Nameless, also called ordinal, parameters are not supported by the .NET Framework Data Provider for SQL Server.
For more information, along with additional sample code demonstrating how to use parameters, see Commands and Parameters.
SqlParameter(String, SqlDbType, Int32, ParameterDirection, Byte, Byte, String, DataRowVersion, Boolean, Object, String, String, String)
Initializes a new instance of the SqlParameter class that uses the parameter name, the type of the parameter, the length of the parameter the direction, the precision, the scale, the name of the source column, one of the DataRowVersion values, a Boolean for source column mapping, the value of the SqlParameter
, the name of the database where the schema collection for this XML instance is located, the owning relational schema where the schema collection for this XML instance is located, and the name of the schema collection for this parameter.
Enforces encryption of a parameter when using Always Encrypted. If SQL Server informs the driver that the parameter does not need to be encrypted, the query using the parameter will fail. This property provides additional protection against security attacks that involve a compromised SQL Server providing incorrect encryption metadata to the client, which may lead to data disclosure.