Serves to load external data into PostgreSQL.
The following example creates an PgSqlLoader, then populates Columns collection from table description, loads data, flushes the buffer and disposes internal PgSqlLoader structures. The PgSqlLoader 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
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