AccessDataSource.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // System.Web.UI.WebControls.AccessDataSource.cs
  3. //
  4. // Authors:
  5. // Sanjay Gupta ([email protected])
  6. //
  7. // (C) 2004 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System.IO;
  31. using System.ComponentModel;
  32. namespace System.Web.UI.WebControls {
  33. [ DesignerAttribute ("System.Web.UI.Design.WebControls.AccessDataSourceDesigner, System.Design",
  34. "System.ComponentModel.Design.IDesigner")]
  35. public class AccessDataSource : SqlDataSource
  36. {
  37. string dataFile;
  38. public AccessDataSource () : base ()
  39. {
  40. this.ProviderName = "System.Data.OleDb";
  41. }
  42. public AccessDataSource (string dataFile, string selectCommand) :
  43. base (String.Empty, selectCommand)
  44. {
  45. this.dataFile = dataFile;
  46. //After setting dataFile, connectionString gets recreated
  47. //On accessing ConnectionString, MS.Net throws NullReferenceException
  48. //Need to dig more on this.
  49. this.ProviderName = "System.Data.OleDb";
  50. }
  51. protected override SqlDataSourceView CreateDataSourceView (string viewName)
  52. {
  53. AccessDataSourceView view = new AccessDataSourceView (this, viewName, this.Context);
  54. view.DataSourceViewChanged += new EventHandler (ViewChanged);
  55. if (IsTrackingViewState)
  56. ((IStateManager) view).TrackViewState ();
  57. return view;
  58. }
  59. void ViewChanged (object source, EventArgs e)
  60. {
  61. OnDataSourceChanged (e);
  62. }
  63. /*[MonoTODO]
  64. protected internal override void SaveDataToCache (int startingRowIndex,
  65. int maxRows, object data)
  66. {
  67. throw new NotImplementedException ();
  68. }
  69. [MonoTODO]
  70. protected internal override void SaveTotalRowCountToCache(int totalRows)
  71. {
  72. throw new NotImplementedException ();
  73. }
  74. public override string SqlCacheDependency {
  75. get { throw new NotSupportedException ("AccessDataSource does not supports SQL Cache Dependencies."); }
  76. set { throw new NotSupportedException ("AccessDataSource does not supports SQL Cache Dependencies."); }
  77. }*/
  78. //Above commented out portion will come into place after implementing
  79. // stuff in SqlDataSource class.
  80. //Overrid implementation will depend on how .Net stores data in
  81. //Cache property of HttpContext object.
  82. [BrowsableAttribute (false),
  83. DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  84. public override string ConnectionString {
  85. get { return this.ConnectionString; }
  86. set { throw new InvalidOperationException
  87. ("The ConnectionString is automatically generated for AccessDataSource and hence cannot be set.");
  88. }
  89. }
  90. [UrlPropertyAttribute (), DefaultValueAttribute (""),
  91. WebCategoryAttribute ("Data"),
  92. WebSysDescriptionAttribute ("MS Office Access database file name"),
  93. EditorAttribute ("System.Web.UI.Design.MdbDataFileEditor, System.Design",
  94. "System.Drawing.Design.UITypeEditor, System.Drawing")]
  95. public string DataFile {
  96. get { return dataFile; }
  97. set { dataFile = value; }
  98. //After setting dataFile, connectionString gets recreated
  99. //On accessing ConnectionString, MS.Net throws NullReferenceException
  100. //Need to dig more on this.
  101. }
  102. [BrowsableAttribute (false),
  103. DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  104. public override string ProviderName {
  105. get { return this.ProviderName; }
  106. set { throw new InvalidOperationException
  107. ("Setting ProviderName on an AccessDataSource is not allowed");
  108. }
  109. }
  110. }
  111. }
  112. #endif