dotConnect for PostgreSQL Documentation
CommandText Property
See Also  Example support@devart.com
Devart.Data.PostgreSql Namespace > PgSqlCommand Class : CommandText Property

Gets or sets the SQL statement to execute against PostgreSQL.

Syntax

Visual Basic (Declaration) 
Public Overrides Property CommandText As String
C# 
public override string CommandText {get; set;}

Property Value

The SQL statement or stored procedure to execute. The default value is an empty string ("").

When working with overloaded stored procedures, use following syntax for executing specific overloaded routine: "StoredProcName:1" or "StoredProcName:5". First example executes first overloaded stored procedure, while second example executes fifth overloaded procedure. This notation affects only describing procedures when P:Devart.Data.DbCommandBase.ParameterCheck is true.

If P:Devart.Data.DbCommandBase.ParameterCheck is false, for a stored procedure, you need to explicitly specify that you are calling a procedure, and not a function. This is done by adding the ':proc' suffix to theprocedure name. For example, "StoredProcName:proc". You don't need to add this suffix for a stored function.

Remarks

Sense of CommandText property depends on value of CommandType property.

When CommandType value is System.Data.CommandType.Text, property CommandText should contain text of a query that must be run on the server. It also may contain several SQL statements, separated with the semicolon. You may use parameters in all the statements. If there are several statements, returning data, use PgSqlDataReader.NextResult to get all reader results.

When the value is System.Data.CommandType.StoredProcedure, property CommandText must be a name of a procedure to execute.

When the value is set to System.Data.CommandType.TableDirect, CommandText must be name of a table you want to get all data from. All rows and columns are retrieved.

Example

The following example creates a PgSqlCommand and sets some of its properties.
C#csharpCopy Code
public void CreateCommand()
{
  PgSqlCommand pgCommand = new PgSqlCommand();
  pgCommand.CommandText = "SELECT * FROM Test.Dept ORDER BY DeptNo";
}
C#Visual BasicCopy Code
Public Sub CreateCommand()
  Dim pgCommand As New PgSqlCommand()
  pgCommand.CommandText = "SELECT * FROM Test.Dept ORDER BY DeptNo"
End Sub

Requirements

Platforms:Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8, Windows 10, Windows Server 2012 family.

See Also