Represents a parameter to a
SqlCommand, and optionally, its mapping to
System.Data.DataSet columns.
The following example creates multiple instances of
SqlParameter through the
SqlParameterCollection within the
SqlDataAdapter. These parameters are used to select data from SQL Server and place the data in the
System.Data.DataSet. This example assumes that a
System.Data.DataSet and a
SqlDataAdapter have already been created with the appropriate schema, commands, and connection.
public void AddSqlParameters()
{
// ...
// create myDataSet and myDataAdapter
// ...
myDataAdapter.SelectCommand.Parameters.Add("DName", SqlType.VarChar, 15).Value = "DEVELOPMENT";
myDataAdapter.SelectCommand.Parameters.Add("DeptNo", SqlType.Int).Value = 50;
myDataAdapter.Fill(myDataSet);
}
Public Sub AddSqlParameters()
' ...
' create myDataSet and myDataAdapter
' ...
myDataAdapter.SelectCommand.Parameters.Add("DName", SqlType.VarChar, 15).Value = "DEVELOPMENT"
myDataAdapter.SelectCommand.Parameters.Add("DeptNo", SqlType.Int).Value = 50
myDataAdapter.Fill(myDataSet)
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2