dotConnect for DB2 Documentation
Devart.Data.DB2 Namespace / DB2Command Class / Parameters Property
Example

In This Topic
    Parameters Property
    In This Topic
    Gets or sets the DB2ParameterCollection.
    Syntax
    'Declaration
     
    Public Shadows ReadOnly Property Parameters As DB2ParameterCollection
    public new DB2ParameterCollection Parameters {get;}

    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 DB2 for detailed information on using this mode.
    Example
    The following example creates a DB2Connection, DB2Command, fills its parameters and displays them. An UPDATE statement with the parameters involved is executed then.
    static void CreateCommand(DB2Connection db2Connection, string mySelectQuery, DB2Parameter[] myParamArray)
    {
      DB2Command db2Command = new DB2Command(mySelectQuery, db2Connection);
      string myMessage = "";
      for (int i = 0; i < myParamArray.Length; i++)
      {
        db2Command.Parameters.Add(myParamArray[i]);
        myMessage += db2Command.Parameters[i].ToString() + "\n";
      }
      Console.Write(myMessage);
      try
      {
        db2Connection.Open();
        db2Command.ExecuteNonQuery();
      }
      finally
      {
        db2Connection.Close();
      }
    }
    
    static void Main(string[] args)
    {
      DB2Parameter[] myParams = new DB2Parameter[] 
        {
          new DB2Parameter("DeptNo", 10),
          new DB2Parameter("DName", "COUNTING")
        };
      DB2Connection db2Connection1 = new DB2Connection(
          "user id=db2admin;server=db2;database=SAMPLE;");
      CreateCommand(db2Connection1,"UPDATE Dept SET DName = :DName WHERE DeptNo = :DeptNo",myParams);
    }
    Public Sub CreateCommand(ByVal db2Connection As Devart.Data.DB2.DB2Connection, _
     ByVal mySelectQuery As String, ByVal myParamArray() As Devart.Data.DB2.DB2Parameter)
      Dim db2Command As New Devart.Data.DB2.DB2Command(mySelectQuery, db2Connection)
      Dim myMessage As String = ""
      Dim i As Integer
      For i = 0 To (myParamArray.Length - 1)
        db2Command.Parameters.Add(myParamArray(i))
        myMessage = String.Concat(myMessage, " ", db2Command.Parameters(i).ToString())
      Next
      Console.WriteLine(myMessage)
      Try
        db2Connection.Open()
        db2Command.ExecuteNonQuery()
      Finally
        db2Connection.Close()
      End Try
    End Sub
    
    Sub Main()
      Dim myP1 As New Devart.Data.DB2.DB2Parameter
      myP1.ParameterName = "DeptNo"
      myP1.Value = 10
      Dim myP2 As New Devart.Data.DB2.DB2Parameter
      myP2.ParameterName = "DName"
      myP2.Value = "ACCOUNTING"
      Dim myParams(1) As Devart.Data.DB2.DB2Parameter
      myParams(0) = myP1
      myParams(1) = myP2
      Dim db2Connection1 As New Devart.Data.DB2.DB2Connection( _
          "user id=db2admin;server=db2;database=SAMPLE;")
      CreateCommand(db2Connection1, "UPDATE 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