当前位置: 首页>>代码示例>>C#>>正文


C# SafeDataReader.GetBytes方法代码示例

本文整理汇总了C#中Csla.Data.SafeDataReader.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# SafeDataReader.GetBytes方法的具体用法?C# SafeDataReader.GetBytes怎么用?C# SafeDataReader.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Csla.Data.SafeDataReader的用法示例。


在下文中一共展示了SafeDataReader.GetBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetBytes

        /// <summary>
        /// Returns the Bytes stored in a binary column.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="columnName">The column name.</param>
        /// <returns>Bytes Stored in a column.</returns>
        public static byte[] GetBytes(SafeDataReader reader, string columnName)
        {
            var buffer = new byte[1024];
            long fieldOffset = 0;
            
            using (var stream = new MemoryStream())
            {
                long bytesRead;

                while ((bytesRead = reader.GetBytes(columnName, fieldOffset, buffer, 0, buffer.Length)) > 0)
                {
                    var actualRead = new byte[bytesRead];
                    Buffer.BlockCopy(buffer, 0, actualRead, 0, (int)bytesRead);
                    stream.Write(actualRead, 0, actualRead.Length);
                    fieldOffset += bytesRead;
                }

                return stream.ToArray();
            }
        }
开发者ID:codesmithtools,项目名称:Framework-Samples,代码行数:26,代码来源:ADOHelper.cs

示例2: CopyIcons

        /// <summary>
        /// The copy icons.
        /// </summary>
        public override Dictionary<string, byte[]> CopyIcons()
        {
            var values = new List<string>();
            var items = new Dictionary<string, byte[]>();
            const string commandText = @"
SELECT [Id]
      ,[Name]
      ,[Description]
      ,[Icon]
      ,[fa_alternative]
  FROM [dbo].[Icons]
";
            using (var ctx = GetMetaDatabaseConnectionManager())
            {
                using (var cmd = new SqlCommand(commandText, ctx.Connection))
                {
                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        while (reader.Read())
                        {
                            var filenameOrigin = reader.GetString(1);
                            var data = reader.GetBytes(3);

                            var filename = string.Format("{0}.png", filenameOrigin.Trim());

                            if (!items.ContainsKey(filename) && filename != ".png")
                            {
                                items.Add(filename, (byte[])data);
                            }

                            values.Add(string.Format("({0},'{1}','{2}', NULL,'{3}')", reader.GetInt32(0), filenameOrigin.Trim(), reader.GetString(2), reader.GetString(4)));
                        }
                    }
                }
            }

            var script = string.Format(@"   SET IDENTITY_INSERT __Icon ON
MERGE INTO [dbo].[__Icon] AS TARGET USING (
    VALUES {0}
                                                     ) 
        AS Source([Id], [Name], [Description], [Icon], [fa_alternative]) ON TARGET.id = Source.Id -- update matched rows
 WHEN MATCHED THEN
UPDATE
SET [Name] = Source.[Name],
    [Description] = Source.[Description],
    [Icon] = NULL,
    [fa_alternative] = Source.[fa_alternative],
    [IsRemoved] = 0  -- insert new rows
 WHEN NOT MATCHED BY TARGET THEN
INSERT ([Id],
        [Name],
        [Description],
        [Icon],
        [fa_alternative],
        [IsRemoved])
VALUES ([Id],
        [Name],
        [Description],
        NULL,
        [fa_alternative],
        0)

 -- delete rows that are in the target but not the source
WHEN NOT MATCHED BY SOURCE THEN
DELETE ;

SET IDENTITY_INSERT __Icon OFF
", string.Join(",", values));

            ExecuteSql(script);
            return items;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:75,代码来源:SqlServerDatabaseGenerator.cs


注:本文中的Csla.Data.SafeDataReader.GetBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。