Databases Reference
In-Depth Information
GetXML : This gets XML representation of data in the DataSet, for example:
Console.WriteLine( ds.GetXml() )
ReadXML : This reads XML schema and XML into DataSet, for example:
ds.ReadXML(reader);
WriteXML : This writes XML schema and XML into DataSet, for example:
ds.WriteXml ( ".\\test.xml" ) ;
The short ADO.NET sample C# codes shown in Example 6-1 demonstrate the
use of various DB2 Data Providers.
They perform the same functionality where “selects * from staff” query is issued
and displays the name of the staff (second column in staff table) to the screen.
These sample codes require DB2 Sample database. Key differences between
the codes are highlighted in bold.
DB2 .NET Data Provider C# sample is shown in Example 6-1.
Example 6-1 Short C# sample code using DB2 .NET Data Provider
using System;
using System.Data;
using IBM.Data.DB2;
class NETSamp
{
public static void Main(String[] args)
{
DB2Connection conn = null;
DB2Command cmd = null;
DB2DataReader reader = null;
int cols=0;
bool rows=false;
try{
conn=new DB2Connection ( "Database=SAMPLE" );
Console.WriteLine("\n Connecting to the database.");
// Opening the connection
conn.Open();
// Create the command to be executed
cmd=conn.CreateCommand();
//Prepare the query CommandText.
cmd.CommandText = "SELECT * FROM staff";
Search WWH ::




Custom Search