IfxDataAdapter examples

The first example demonstrates the use of the TableMappings and MissingMappingAction properties.

// IfxConnection -- con
DataSet ds = new DataSet();
string sql = "select fname from customer";
IfxDataAdapter da = new IfxDataAdapter(sql,con);
// Default -- MissingMappingAction set to Passthrough.
// Database Column name is used as Data Set Column Name. This 
//is the default setting
//da.MissingMappingAction = MissingMappingAction.Passthrough;
// MissingMappingAction set to Ignore
// The column or table not having a mapping is ignored. Returns a 
// null reference . Will return error while accessing DataRow 
da.MissingMappingAction = MissingMappingAction.Ignore;
// MissingMappingAction set to Error 
// DataColumnMapping & DataTableMapping is not done 
// then DataAdapter.Fill  returns Exception
da.MissingMappingAction = MissingMappingAction.Error;
// If set to Error, DataColumnMapping and DataTableMapping has to 
// be done
DataColumnMapping dcFnm = new DataColumnMapping("fname", "FirstName");
DataTableMapping dtCus = new DataTableMapping  ("customer","CustomerTable");
dtCus.ColumnMappings.Add(dcFnm);
// Activates the Mapping
da.TableMappings.Add(dtCus);    
da.Fill(ds,"customer");
foreach(DataRow dr in ds.Tables["CustomerTable"].Rows)
{
      Console.WriteLine(dr["FirstName"]);
}
//Close Connection

The next example demonstrates how to use the FillSchema method in conjunction with the MissingSchemaAction property.

// IfxConnection -- con
DataSet ds = new DataSet();
string sql = "select fname from customer";
IfxDataAdapter da = new IfxDataAdapter(sql,con);
//MissSchemaAction is set to error so Fill will return
// exception if Data Set and Customer table schema
// do not match
da.MissingSchemaAction = MissingSchemaAction.Error;
// Fills Data Set Schema with the customer table schema
da.FillSchema(ds,SchemaType.Source,"customer");
da.Fill(ds,"customer");
foreach(DataRow dr in ds.Tables["customer"].Rows)
{
      Console.WriteLine(dr["fname"]);
}
//Close Connection

The following example illustrates the use of the SelectCommand and UpdateCommand properties.

IfxDataAdapter adpt = new IfxDataAdapter();
adpt.SelectCommand = new IfxCommand("SELECT CustomerID, Name FROM Customers 
    WHERE Country = ? AND City = ?", conn);
IfxParameter ifxp1 = new IfxParameter("Country",DbType.String);
IfxParameter ifxp2 = new IfxParameter("City",DbType.String);
Adpt.SelectCommand.Parameters.Add(ifxp1);
Adpt.SelectCommand.Parameters.Add(ifxp2);
//similarly for an UpdateCommand
//adpt.UpdateCommand.Parameters.Add("CustomerName",DbType.String);
adpt.UpdateCommand.Parameters.["CustomerName"] = "xyz";