TestSqlDataAdapter.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // TestSqlDataAdapter - tests SqlDataAdapter, DbDataAdapter, DataSet, DataTable,
  3. // DataRow, and DataRowCollection by retrieving data
  4. //
  5. // Note: it currently causes an NotImplementException for SqlCommand::NextResult()
  6. //
  7. // Authors:
  8. // Tim Coleman <[email protected]>
  9. // Daniel Morgan <[email protected]>
  10. //
  11. // (c)copyright 2002 Tim Coleman
  12. // (c)copyright 2002 Daniel Morgan
  13. //
  14. using System;
  15. using System.Collections;
  16. using System.Data;
  17. using System.Data.SqlClient;
  18. namespace TestSystemDataSqlClient
  19. {
  20. public class TestSqlDataAdapter
  21. {
  22. public static void Test()
  23. {
  24. string connectionString;
  25. string sqlQuery;
  26. SqlDataAdapter adapter;
  27. DataSet dataSet = null;
  28. connectionString =
  29. "host=localhost;" +
  30. "dbname=test;" +
  31. "user=postgres";
  32. sqlQuery = "select * from pg_tables";
  33. System.Console.WriteLine ("new SqlDataAdapter...");
  34. adapter = new SqlDataAdapter (sqlQuery,
  35. connectionString);
  36. System.Console.WriteLine ("open connection...");
  37. adapter.SelectCommand.Connection.Open ();
  38. System.Console.WriteLine ("new DataSet...");
  39. dataSet = new DataSet ();
  40. try {
  41. System.Console.WriteLine("Fill...");
  42. adapter.Fill (dataSet);
  43. }
  44. catch (NotImplementedException e) {
  45. Console.WriteLine("Exception Caught: " + e);
  46. }
  47. System.Console.WriteLine ("get row...");
  48. if (dataSet != null) {
  49. foreach (DataRow row in dataSet.Tables["Table"].Rows)
  50. Console.WriteLine("tablename: " + row["tablename"]);
  51. System.Console.WriteLine("Done.");
  52. }
  53. }
  54. public static void Main()
  55. {
  56. Test();
  57. }
  58. }
  59. }