Posted By


mn232nm on 11/02/08

Tagged


Statistics


Viewed 509 times
Favorited by 0 user(s)

AccessHelperParameterCache


/ Published in: C#
Save to your folder(s)

AccessHelperParameterCache


Copy this code and paste it in your HTML
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.OleDb;
  6. using System.Text;
  7.  
  8. namespace Web.DataAccess
  9. {
  10. public sealed class AccessHelperParameterCache
  11. {
  12. private AccessHelperParameterCache() { }
  13.  
  14. private static OleDbParameter[] CloneParameters(OleDbParameter[] originalParameters)
  15. {
  16. OleDbParameter[] cloneParameters = new OleDbParameter[originalParameters.Length];
  17. for (int i = 0; i < cloneParameters.Length; i++)
  18. {
  19. cloneParameters[i] = (OleDbParameter)(((ICloneable)originalParameters[i]).Clone());
  20. }
  21.  
  22. return cloneParameters;
  23. }
  24.  
  25. private static Hashtable paramCache = Hashtable.Synchronized(new Hashtable());
  26.  
  27. public static void CacheParameterSet(string connectionString, string commandText, params OleDbParameter[] commandParameters)
  28. {
  29. if (null == connectionString || string.Empty == connectionString) throw new ArgumentNullException("connectionString");
  30. if (null == commandText || string.Empty == commandText) throw new ArgumentNullException("commandText");
  31. if (null == commandParameters || 0 == commandParameters.Length) throw new ArgumentNullException("commandParameters");
  32.  
  33. paramCache[connectionString + ":" + commandText] = CloneParameters(commandParameters);
  34. }
  35.  
  36. public static OleDbParameter[] GetCacheParameterSet(string connectionString, string commandText)
  37. {
  38. if (null == connectionString || string.Empty == connectionString) throw new ArgumentNullException("connectionString");
  39. if (null == commandText || string.Empty == commandText) throw new ArgumentNullException("commandText");
  40.  
  41. OleDbParameter[] cachedParameters = paramCache[connectionString + commandText] as OleDbParameter[];
  42. if (null != cachedParameters)
  43. {
  44. CloneParameters(cachedParameters);
  45. }
  46. return null;
  47. }
  48. }
  49. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.