public void UseDataAdapter(PgSqlConnection pgConnection)
{
PgSqlDataAdapter myAdapter = new PgSqlDataAdapter("SELECT DeptNo, DName FROM Test.Dept", pgConnection);
myAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataSet myDataSet = new DataSet();
myAdapter.Fill(myDataSet,"Departments");
object[] rowVals = new object[2];
rowVals[0] = 40;
rowVals[1] = "Operations";
myDataSet.Tables["Departments"].Rows.Add(rowVals);
myAdapter.InsertCommand = new PgSqlCommand("INSERT INTO Test.Dept (DeptNo, DName) " +
"VALUES (:DeptNo, :DName)", pgConnection);
myAdapter.InsertCommand.Parameters.Add("DeptNo", PgSqlType.Int, 0, "DeptNo");
myAdapter.InsertCommand.Parameters.Add("DName", PgSqlType.VarChar, 15, "DName");
myAdapter.Update(myDataSet,"Departments");
//Get all data from all tables within the dataset
foreach(DataTable myTable in myDataSet.Tables)
{
foreach(DataRow myRow in myTable.Rows)
{
foreach (DataColumn myColumn in myTable.Columns)
{
Console.Write(myRow[myColumn]+"\t");
}
Console.WriteLine();
}
Console.WriteLine();
}
}