/ Published in: C#
AccessHelperParameterCache
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Text; namespace Web.DataAccess { public sealed class AccessHelperParameterCache { private AccessHelperParameterCache() { } private static OleDbParameter[] CloneParameters(OleDbParameter[] originalParameters) { for (int i = 0; i < cloneParameters.Length; i++) { cloneParameters[i] = (OleDbParameter)(((ICloneable)originalParameters[i]).Clone()); } return cloneParameters; } public static void CacheParameterSet(string connectionString, string commandText, params OleDbParameter[] commandParameters) { if (null == connectionString || string.Empty == connectionString) throw new ArgumentNullException("connectionString"); if (null == commandText || string.Empty == commandText) throw new ArgumentNullException("commandText"); if (null == commandParameters || 0 == commandParameters.Length) throw new ArgumentNullException("commandParameters"); paramCache[connectionString + ":" + commandText] = CloneParameters(commandParameters); } public static OleDbParameter[] GetCacheParameterSet(string connectionString, string commandText) { if (null == connectionString || string.Empty == connectionString) throw new ArgumentNullException("connectionString"); if (null == commandText || string.Empty == commandText) throw new ArgumentNullException("commandText"); OleDbParameter[] cachedParameters = paramCache[connectionString + commandText] as OleDbParameter[]; if (null != cachedParameters) { CloneParameters(cachedParameters); } return null; } } }