9. Understanding .NET Data Provider Connectivity : .NET Data Provider Classes : Sample Program Constructed with .NET Data Provider : .NET 1.1 Programming Model
 
Share this page                  
.NET 1.1 Programming Model
using System;
using System.IO;
using System.Data;
using Ingres.Client;
 
class App
{
static public void Main()
{
string myConnectionString =
"Host=myserver.mycompany.com;" +
"User Id=myname;PWD=mypass;" +
"Database=mydatabase";
IngresConnection conn = new IngresConnection(
myConnectionString );
conn.Open(); // open the Ingres connection
 
string cmdtext = "select table_owner, table_name, " +
"create_date from iitables " +
" where table_type in ('T','V') and " +
" table_name not like 'ii%' and" +
" table_name not like 'II%'";
IngresCommand cmd = new IngresCommand(cmdtext, conn);
 
//          read the data using the DataReader method
IngresDataReader datareader = cmd.ExecuteReader();
 
//          write header labels
Console.WriteLine(datareader.GetName(0).PadRight(18) +
datareader.GetName(1).PadRight(34) +
datareader.GetName(2).PadRight(34));
int i = 0;
while (i++ < 10 && datareader.Read())
// read and write out a few data rows
{     // write out the three columns to the console
        Console.WriteLine(
        datareader.GetString(0).Substring(0,16).PadRight(18) +
        datareader.GetString(1).PadRight(34) +
                datareader.GetString(2));
}
datareader.Close();
DataSet  ds  = new DataSet("my_list_of_tables");
//          read the data using the DataAdapter method
IngresDataAdapter adapter = new IngresDataAdapter();
adapter.SelectCommand = new IngresCommand(cmdtext, conn);
adapter.Fill(ds);  // fill the dataset
 
//          write the dataset to an XML file
ds.WriteXml("c:/temp/temp.xml");
 
conn.Close();   // close the connection
}  // end Main()
}  // end class App