dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleCommand Class / CreateParameter Method
Example

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

    Return Value

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