dotConnect for SQL Server Documentation
Devart.Data.SqlServer Namespace / SqlCommand Class / Parameters Property
Example

Parameters Property
Gets or sets the SqlParameterCollection.
Syntax
'Declaration
 
Public Shadows ReadOnly Property Parameters As SqlParameterCollection
 

Property Value

The parameters of a SQL statement or a stored procedure. The default value is an empty collection.
Remarks
By default, you have to construct this collection and provide values for it manually. However, if you choose to use autosynchronization mode by setting ParameterCheck property to true you can have the collecton adjusted automatically. Please refer to article Using Parameters in dotConnect for SQL Server for detailed information on using this mode.

dotConnect for SQL Server supports named and unnamed parameters.

Example
The following example creates a SqlConnection, SqlCommand, fills its parameters and displays them. An UPDATE statement with the parameters involved is executed then.
static void CreateCommand(SqlConnection myConnection, string mySelectQuery, SqlParameter[] myParamArray)
{
  SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
  string myMessage = "";
  for (int i = 0; i < myParamArray.Length; i++)
  {
    myCommand.Parameters.Add(myParamArray[i]);
    myMessage += myCommand.Parameters[i].ToString() + "\n";
  }
  Console.Write(myMessage);
  try
  {
    myConnection.Open();
    myCommand.ExecuteNonQuery();
  }
  finally
  {
    myConnection.Close();
  }
}

static void Main(string[] args)
{
  SqlParameter[] myParams = new SqlParameter[] 
    {
      new SqlParameter("DeptNo", 10),
      new SqlParameter("DName", "COUNTING")
    };
  SqlConnection myConnection1 = new SqlConnection(
      "User Id=sa;Server=localhost;Initial Catalog=Test;");
  CreateCommand(myConnection1,"UPDATE Test.Dept SET DName = :DName WHERE DeptNo = :DeptNo",myParams);
}
Public Sub CreateCommand(ByVal myConnection As Devart.Data.SqlServer.SqlConnection, _
 ByVal mySelectQuery As String, ByVal myParamArray() As Devart.Data.SqlServer.SqlParameter)
  Dim myCommand As New Devart.Data.SqlServer.SqlCommand(mySelectQuery, myConnection)
  Dim myMessage As String = ""
  Dim i As Integer
  For i = 0 To (myParamArray.Length - 1)
    myCommand.Parameters.Add(myParamArray(i))
    myMessage = String.Concat(myMessage, " ", myCommand.Parameters(i).ToString())
  Next
  Console.WriteLine(myMessage)
  Try
    myConnection.Open()
    myCommand.ExecuteNonQuery()
  Finally
    myConnection.Close()
  End Try
End Sub

Sub Main()
  Dim myP1 As New Devart.Data.SqlServer.SqlParameter
  myP1.ParameterName = "DeptNo"
  myP1.Value = 10
  Dim myP2 As New Devart.Data.SqlServer.SqlParameter
  myP2.ParameterName = "DName"
  myP2.Value = "ACCOUNTING"
  Dim myParams(1) As Devart.Data.SqlServer.SqlParameter
  myParams(0) = myP1
  myParams(1) = myP2
  Dim myConnection1 As New Devart.Data.SqlServer.SqlConnection( _
      "User Id=sa;Server=localhost;Initial Catalog=Test;")
  CreateCommand(myConnection1, "UPDATE Test.Dept SET DName = :DName WHERE DeptNo = :DeptNo", myParams)
End Sub
Requirements

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

See Also