PgSqlCommandBuilder Class
Automatically generates single-table commands used to reconcile changes made to a
System.Data.DataSet with the PostgreSQL.
The following example uses
PgSqlCommand, along with
PgSqlDataAdapter and
PgSqlConnection, to select rows from PostgreSQL. The example is passed an initialized
System.Data.DataSet, a connection string, a query string that is SQL SELECT statement, and a string that is the name of the PostgreSQL table. The example then creates a
PgSqlCommandBuilder.
public DataSet SelectPgSqlSrvRows(DataSet myDataSet,string pgConnection,string mySelectQuery,string myTableName)
{
PgSqlConnection myConn = new PgSqlConnection(pgConnection);
PgSqlDataAdapter myDataAdapter = new PgSqlDataAdapter();
myDataAdapter.SelectCommand = new PgSqlCommand(mySelectQuery, myConn);
PgSqlCommandBuilder pgCommandBuilder = new PgSqlCommandBuilder(myDataAdapter);
myConn.Open();
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet, "Departments");
//code to modify data in dataset here
//Without the PgSqlCommandBuilder this line would fail
myDataAdapter.Update(myDataSet, "Departments");
myConn.Close();
return myDataSet;
}
Public Function SelectPgSqlSrvRows(myDataSet As DataSet, pgConnection As String, mySelectQuery As String, myTableName As String) As DataSet
Dim myConn As New PgSqlConnection(pgConnection)
Dim myDataAdapter As New PgSqlDataAdapter()
myDataAdapter.SelectCommand = New PgSqlCommand(mySelectQuery, myConn)
Dim pgCommandBuilder As PgSqlCommandBuilder = New PgSqlCommandBuilder(myDataAdapter)
myConn.Open()
Dim myDataSet As DataSet = New DataSet
myDataAdapter.Fill(myDataSet, "Departments")
' Code to modify data in DataSet here
' Without the PgSqlCommandBuilder this line would fail.
myDataAdapter.Update(myDataSet, "Departments")
myConn.Close()
SelectPgSqlSrvRows = myDataSet
End Function
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