Esempio n. 1
0
        /// <summary>
        /// Another pattern that is refactored here
        /// Given ADODB.Recordset return a string of its xml
        /// </summary>
        /// <param name="record">The record.</param>
        /// <returns></returns>
        static internal string GetXmlFromAdoRecordset(_Recordset record)
        {
            var     results = String.Empty;
            _Stream stream  = null;

            try
            {
                if (null != record)
                {
                    stream = new Stream();
                    record.Save(stream, PersistFormatEnum.adPersistXML);
                    results = stream.ReadText(-1);
                }
            }
            catch (Exception ex)
            {
                LogError("GetXmlFromAdoRecordset(): Error " + ex.Message, "GetXmlFromAdoRecordset");
            }
            finally
            {
                if (stream != null)
                {
                    Marshal.ReleaseComObject(stream);
                }
            }
            return(results);
        }
Esempio n. 2
0
        static public _Recordset GetRecordsetFromXml(string xml)
        {
            _Stream stream = null;

            try
            {
                stream = new ADODB.Stream();
                stream.Open(Missing.Value, ConnectModeEnum.adModeUnknown, StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "");
                stream.WriteText(xml, StreamWriteEnum.adWriteChar);
                stream.Position = 0;

                var recordset = new Recordset();
                recordset.Open(stream, Missing.Value, CursorTypeEnum.adOpenUnspecified, LockTypeEnum.adLockUnspecified, 0);
                return(recordset);
            }
            catch (Exception ex)
            {
                ErrorLog.LogError(ex, new CallingMethod());
                return(default(_Recordset));
            }
            finally
            {
                if (stream != null)
                {
                    Marshal.ReleaseComObject(stream);
                }
            }
        }