2 using System.Data.OleDb;
4 namespace System.Data.OleDb.Test
8 private OleDbConnection m_cnc;
14 m_cnc = new OleDbConnection ("PostgreSQL");
17 Console.WriteLine ("Creating temporary table...");
18 cmd = new OleDbCommand ("CREATE TABLE mono_test_table ( " +
19 " name varchar(25), email varchar(50), date_entered timestamp)",
21 cmd.ExecuteNonQuery ();
22 InsertRow ("Mike Smith", "mike@smiths.com");
23 InsertRow ("Julie Andrews", "julie@hollywood.com");
24 InsertRow ("Michael Jordan", "michael@bulls.com");
27 void InsertRow (string name, string email)
31 cmd = new OleDbCommand ("INSERT INTO mono_test_table (name, email, date_entered) VALUES ('" +
32 name + "', '" + email +"', date 'now')", m_cnc);
33 Console.WriteLine ("Executing command '" + cmd.CommandText + "'");
34 cmd.ExecuteNonQuery ();
38 void DisplayRow (OleDbDataReader reader)
40 for (int i = 0; i < reader.FieldCount; i++) {
41 Console.WriteLine (" " + reader.GetDataTypeName (i) + ": " +
42 reader.GetValue (i).ToString ());
46 void TestDataReader ()
49 string sql = "SELECT * FROM mono_test_table";
51 Console.WriteLine ("Executing SELECT command...");
52 OleDbCommand cmd = new OleDbCommand (sql, m_cnc);
53 OleDbDataReader reader = cmd.ExecuteReader ();
55 Console.WriteLine (" Recordset description:");
56 for (i = 0; i < reader.FieldCount; i++) {
57 Console.WriteLine (" Field " + i + ": " +
58 reader.GetName (i) + " (" +
59 reader.GetDataTypeName (i) + ")");
62 Console.WriteLine ("Reading data...");
64 while (reader.Read ()) {
65 Console.WriteLine ("Row " + i + ":");
71 void TestTransaction ()
73 Console.WriteLine ("Starting transaction...");
74 OleDbTransaction xaction = m_cnc.BeginTransaction ();
76 Console.WriteLine ("Aborting transaction...");
82 OleDbCommand cmd = new OleDbCommand ("DROP TABLE mono_test_table", m_cnc);
83 cmd.ExecuteNonQuery ();
87 static void Main (string[] args)
90 TestOleDb test = new TestOleDb ();
91 test.TestDataReader ();
92 test.TestTransaction ();
94 } catch (Exception e) {
95 Console.WriteLine ("An error has occured: {0}", e.ToString ());