See Also

PgSqlCommand Class  | PgSqlCommand Members  | PgSqlParameter Class  | CommandText Property

Language

Visual Basic

C#

Show All

See AlsoLanguagesDevart.Data.PostgreSqlSend comments on this topic.

Parameters Property

Devart.Data.PostgreSql Namespace > PgSqlCommand Class : Parameters Property

Gets or sets the PgSqlParameterCollection.

[Visual Basic]
Public ReadOnly Property Parameters As PgSqlParameterCollection
[C#]
public PgSqlParameterCollection Parameters {get;}

Return Type

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 Devart.Common.DbCommandBase.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.

[C#] 

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); 

[Visual Basic] 

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

See Also

PgSqlCommand Class  | PgSqlCommand Members  | PgSqlParameter Class  | CommandText Property

 

 


© 2003 - 2014 Devart. All Rights Reserved.