TestSqlDataAdapter.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // TestPgSqlDataAdapter - tests PgSqlDataAdapter, DbDataAdapter, DataSet, DataTable,
  3. // DataRow, and DataRowCollection by retrieving data
  4. //
  5. // Authors:
  6. // Tim Coleman <[email protected]>
  7. // Daniel Morgan <[email protected]>
  8. //
  9. // (c)copyright 2002 Tim Coleman
  10. // (c)copyright 2002 Daniel Morgan
  11. //
  12. //
  13. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. using System;
  35. using System.Collections;
  36. using System.Data;
  37. using Mono.Data.PostgreSqlClient;
  38. namespace TestSystemDataPgSqlClient
  39. {
  40. public class TestPgSqlDataAdapter
  41. {
  42. public static void Test()
  43. {
  44. string connectionString;
  45. string sqlQuery;
  46. PgSqlDataAdapter adapter;
  47. DataSet dataSet = null;
  48. connectionString =
  49. "host=localhost;" +
  50. "dbname=test;" +
  51. "user=postgres";
  52. sqlQuery = "select * from pg_tables";
  53. System.Console.WriteLine ("new PgSqlDataAdapter...");
  54. adapter = new PgSqlDataAdapter (sqlQuery,
  55. connectionString);
  56. System.Console.WriteLine ("new DataSet...");
  57. dataSet = new DataSet ();
  58. try {
  59. System.Console.WriteLine("Fill...");
  60. adapter.Fill (dataSet);
  61. }
  62. catch (NotImplementedException e) {
  63. Console.WriteLine("Exception Caught: " + e);
  64. }
  65. System.Console.WriteLine ("get row...");
  66. if (dataSet != null) {
  67. foreach (DataRow row in dataSet.Tables["Table"].Rows)
  68. Console.WriteLine("tablename: " + row["tablename"]);
  69. System.Console.WriteLine("Done.");
  70. }
  71. }
  72. public static void Main()
  73. {
  74. Test();
  75. }
  76. }
  77. }