14.01.2013 Views

IBM Informix Developer's Handbook - IBM Redbooks

IBM Informix Developer's Handbook - IBM Redbooks

IBM Informix Developer's Handbook - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table 8-9 lists the methods that the IfxDataAdapter class provides for accessing<br />

the data.<br />

Table 8-9 IfxDataAdapter public methods<br />

Method Description<br />

Int32 Fill(DataSet) Adds or refreshes rows in the data set<br />

DataTable FillSchema(DataSet,<br />

SchemaType)<br />

IDataParameter<br />

GetFillParameters()<br />

Example 8-10 demonstrates how to retrieve data from the database using the<br />

IfxDataAdapter class. In this example, we retrieve the data rows directly from the<br />

data set.<br />

Example 8-10 The dataadapter_sample.cs sample<br />

using System;<br />

using System.Data;<br />

using <strong>IBM</strong>.Data.<strong>Informix</strong>;<br />

class sample {<br />

static void Main(string[] args) {<br />

IfxConnection conn;<br />

268 <strong>IBM</strong> <strong>Informix</strong> Developer’s <strong>Handbook</strong><br />

conn = new IfxConnection("Server=demo_on;database=stores_demo");<br />

conn.Open();<br />

IfxCommand cmmd = conn.CreateCommand();<br />

cmmd.CommandText = "SELECT * FROM state WHERE code='CA'";<br />

IfxDataAdapter dadap = new IfxDataAdapter();<br />

DataSet dset = new DataSet();<br />

dadap.SelectCommand = cmmd;<br />

dadap.Fill(dset);<br />

Adds a data table to the data set, and<br />

configures the schema to match that in the<br />

database based on the specified SchemaType<br />

Returns the parameters set by the user when<br />

executing a SELECT statement<br />

Int32 Update(DataSet) Executes the SQL statement that is associated<br />

with the InsertCommand, UpdateCommand, or<br />

DeleteCommand for each inserted, updated, or<br />

deleted row in the specified data set<br />

foreach(DataRow dr in dset.Tables[0].Rows) {<br />

Console.WriteLine(String.Format("\tCode\tState\n"));<br />

Console.WriteLine(String.Format("\t{0}\t{1}", dr["code"], dr["sname"]));

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!