System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DbCommand
Devart.Common.DbCommandBase
Devart.Data.PostgreSql.PgSqlCommand
Visual Basic (Declaration) | |
---|---|
Public Class PgSqlCommand Inherits Devart.Common.DbCommandBase Implements IComponent, IDbCommand, ICloneable, IDisposable |
C# | |
---|---|
public class PgSqlCommand : Devart.Common.DbCommandBase, IComponent, IDbCommand, ICloneable, IDisposable |
The PgSqlCommand class provides the following methods for executing commands against the PostgreSQL database:
Item | Description |
---|---|
ExecuteReader | Executes commands that return rows. |
ExecutePageReader | Returns a specific subset of rows when paging through the results of a query. |
ExecuteNonQuery | Executes SQL commands such as INSERT, DELETE, UPDATE. |
ExecuteScalar | Retrieves a single value (for example, an aggregate value) from a data source. |
If execution of the command results in a fatal PgSqlException, the PgSqlConnection may close. However, the user can reopen the connection and continue.
This class supports cross-form data binding with the InterForm Technology.
The following example uses the ExecuteReader method of PgSqlCommand, along with PgSqlDataReader and PgSqlConnection, to select rows from a table.
C#csharp | ![]() |
---|---|
public void ReadMyData(string myConnString) { string mySelectQuery = "SELECT DeptNo, DName FROM Test.Dept"; PgSqlConnection pgConnection = new PgSqlConnection(myConnString); PgSqlCommand pgCommand = new PgSqlCommand(mySelectQuery,pgConnection); pgConnection.Open(); PgSqlDataReader pgReader = pgCommand.ExecuteReader(); try { while (pgReader.Read()) { Console.WriteLine(pgReader.GetInt32(0).ToString() + ", " + pgReader.GetString(1)); } } finally { // always call Close when done reading. pgReader.Close(); // always call Close when done reading. pgConnection.Close(); } } |
C#Visual Basic | ![]() |
---|---|
Public Sub ReadMyData(myConnString As String) Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Test.Dept" Dim pgConnection As New PgSqlConnection(myConnString) Dim pgCommand As New PgSqlCommand(mySelectQuery, pgConnection) pgConnection.Open() Dim pgReader As PgSqlDataReader = pgCommand.ExecuteReader() Try While pgReader.Read() Console.WriteLine(pgReader.GetInt32(0).ToString() + ", " _ + pgReader.GetString(1)) End While Finally ' always call Close when done reading. pgReader.Close() ' always call Close when done with connection. pgConnection.Close() End Try End Sub |
Requirements
Namespace: Devart.Data.PostgreSql
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.