dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlLoader Class
Members Example

In This Topic
    PgSqlLoader Class
    In This Topic
    Serves to load external data into PostgreSQL.
    Syntax
    'Declaration
     
    Public NotInheritable Class PgSqlLoader 
       Inherits Devart.Common.DbLoader
       Implements System.ComponentModel.IComponentSystem.IDisposable 
    Remarks

    PgSqlLoader uses special capabilities of PostgreSQL server (the COPY command) to speed up loading of many rows into a table.

    To specify the name of loading table set TableName property. Use Columns property to access individual columns.

    This class is available only in Professional Edition. It is not available in Standard and Mobile Editions.

    Example

    The following example creates an Devart.Data.Oracle.OracleLoader, then populates Columns collection from table description, loads data, flushes the buffer and disposes internal Devart.Data.Oracle.OracleLoader structures. The Devart.Data.Oracle.OracleLoader requires open connection.

    The following table is used in this example:

    CREATE TABLE load_table
    (
     id integer NOT NULL,
     text_field text,
     date_field date,
     CONSTRAINT load_table_pkey PRIMARY KEY (id)
    )
    
    public void LoadData(PgSqlConnection conn)
    {
            // PgSqlLoader requires open connection 
            if (conn.State == ConnectionState.Closed)
                    conn.Open();
            PgSqlLoader loader = new PgSqlLoader();
            // Specify connection that PgSqlLoader will use for loading 
            loader.Connection = conn;
            // Set table name that will be loaded into 
            loader.TableName = "load_table";
            // Populate Columns collection from table description 
            loader.CreateColumns();
            // Prepare PgSqlLoader for loading 
            loader.Open();
            for (int i = 0; i < 10000; i++)
            {
                    loader.SetValue("id", i);
                    loader.SetValue("text_field", "test string");
                    loader.SetValue("date_field", DateTime.Now);
                    loader.NextRow();
            }
            // Flush buffer and dispose internal PgSqlLoader structures 
            loader.Close();
    }
    Public Sub LoadData(conn As PgSqlConnection)
            ' PgSqlLoader requires open connection
            If conn.State = ConnectionState.Closed Then
                    conn.Open()
            End If
            Dim loader As PgSqlLoader
            loader = New PgSqlLoader
            ' Specify connection that PgSqlLoader will use for loading
            loader.Connection = conn
            ' Set table name that will be loaded into
            loader.TableName = "load_table" 
            ' Populate Columns collection from table description
            loader.CreateColumns()
            ' Prepare PgSqlLoader for loading
            loader.Open()
            Dim i As Integer
            For i = 0 To 9999
                    loader.SetValue("id", i)
                    loader.SetValue("text_field", "test string")
                    loader.SetValue("date_field", DateTime.Now)
                    loader.NextRow()
            Next i
            ' Flush buffer and dispose internal PgSqlLoader structures
            loader.Close()
    End Sub
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             Devart.Common.DbLoader
                Devart.Data.PostgreSql.PgSqlLoader

    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