dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlCommand Class / CreateParameter Method
Example

In This Topic
    CreateParameter Method (PgSqlCommand)
    In This Topic
    Creates a new instance of a PgSqlParameter object.
    Creates a new instance of a PgSqlParameter object.
    Syntax
    'Declaration
     
    Public Shadows Function CreateParameter() As PgSqlParameter
    public new PgSqlParameter CreateParameter()

    Return Value

    A PgSqlParameter object.
    Remarks
    This method is a strongly-typed version of System.Data.IDbCommand.CreateParameter. See PgSqlParameter to find out more ways to create a parameter.
    Example
    This sample shows how to create a parameter using CreateParameter function.
    Public void CreateParam(PgSqlConnection pgConnection)
    {
      PgSqlCommand pgCommand = new PgSqlCommand("SELECT * FROM Test.Dept WHERE DeptNo=:Deptno",pgConnection);
      PgSqlParameter myParam = pgCommand.CreateParameter();
      myParam.PgSqlType = Devart.Data.PostgreSql.PgSqlType.Int;
      myParam.Value = 10;
      myParam.ParameterName = "Deptno";
      pgCommand.Parameters.Add(myParam);
      pgConnection.Open();
      PgSqlDataReader pgReader = null; 
      try
      {
        pgReader = pgCommand.ExecuteReader(); 
        while (pgReader.Read())
        {
          Console.WriteLine(pgReader.GetInt32(0) + ", " + pgReader.GetString(1) + ", " + pgReader.GetString(2));
        }
      }
      finally
      {
        pgReader.Close();
        pgConnection.Close();
      }
    }
    Public Sub CreateParam(ByVal pgConnection As PgSqlConnection)
      Dim pgCommand As New PgSqlCommand("SELECT * FROM Test.Dept WHERE DeptNo=:Deptno", pgConnection)
      Dim myParam As PgSqlParameter = pgCommand.CreateParameter()
      myParam.PgSqlType = Devart.Data.PostgreSql.PgSqlType.Int
      myParam.Value = 10
      myParam.ParameterName = "Deptno"
      pgCommand.Parameters.Add(myParam)
      pgConnection.Open()
      Dim pgReader As PgSqlDataReader = Nothing
      Try
        pgReader = pgCommand.ExecuteReader()
        While pgReader.Read()
          Console.WriteLine(pgReader.GetInt32(0).ToString() + ", " _
            + pgReader.GetString(1) + ", " _
            + pgReader.GetString(2))
        End While
      Finally
        pgReader.Close()
        pgConnection.Close()
      End Try
    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