dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlCommand Class / Parameters Property
Example

In This Topic
    Parameters Property
    In This Topic
    Gets or sets the PgSqlParameterCollection.
    Syntax
    'Declaration
     
    Public Shadows ReadOnly Property Parameters As PgSqlParameterCollection
    public new PgSqlParameterCollection 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 PostgreSQL for detailed information on using this mode.
    Example
    The following example creates a PgSqlConnection, PgSqlCommand, fills its parameters and displays them. An UPDATE statement with the parameters involved is executed then.
    static void CreateCommand(PgSqlConnection pgConnection, string mySelectQuery, PgSqlParameter[] myParamArray)
    {
      PgSqlCommand pgCommand = new PgSqlCommand(mySelectQuery, pgConnection);
      string myMessage = "";
      for (int i = 0; i < myParamArray.Length; i++)
      {
        pgCommand.Parameters.Add(myParamArray[i]);
        myMessage += pgCommand.Parameters[i].ToString() + "\n";
      }
      Console.Write(myMessage);
      try
      {
        pgConnection.Open();
        pgCommand.ExecuteNonQuery();
      }
      finally
      {
        pgConnection.Close();
      }
    }
    
    static void Main(string[] args)
    {
      PgSqlParameter[] myParams = new PgSqlParameter[] 
        {
          new PgSqlParameter("DeptNo", 10),
          new PgSqlParameter("DName", "COUNTING")
        };
      PgSqlConnection pgConnection1 = new PgSqlConnection(
          "host=server;database=test;user id=postgres;");
      CreateCommand(pgConnection1,"UPDATE Test.Dept SET DName = :DName WHERE DeptNo = :DeptNo",myParams);
    }
    Public Sub CreateCommand(ByVal pgConnection As Devart.Data.PostgreSql.PgSqlConnection, _
     ByVal mySelectQuery As String, ByVal myParamArray() As Devart.Data.PostgreSql.PgSqlParameter)
      Dim pgCommand As New Devart.Data.PostgreSql.PgSqlCommand(mySelectQuery, pgConnection)
      Dim myMessage As String = ""
      Dim i As Integer
      For i = 0 To (myParamArray.Length - 1)
        pgCommand.Parameters.Add(myParamArray(i))
        myMessage = String.Concat(myMessage, " ", pgCommand.Parameters(i).ToString())
      Next
      Console.WriteLine(myMessage)
      Try
        pgConnection.Open()
        pgCommand.ExecuteNonQuery()
      Finally
        pgConnection.Close()
      End Try
    End Sub
    
    Sub Main()
      Dim myP1 As New Devart.Data.PostgreSql.PgSqlParameter
      myP1.ParameterName = "DeptNo"
      myP1.Value = 10
      Dim myP2 As New Devart.Data.PostgreSql.PgSqlParameter
      myP2.ParameterName = "DName"
      myP2.Value = "ACCOUNTING"
      Dim myParams(1) As Devart.Data.PostgreSql.PgSqlParameter
      myParams(0) = myP1
      myParams(1) = myP2
      Dim pgConnection1 As New Devart.Data.PostgreSql.PgSqlConnection( _
          "host=server;database=test;user id=postgres;")
      CreateCommand(pgConnection1, "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