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


C# SqlDataRecord.SetInt64方法代码示例

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


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

示例1: CreateBigIdentityIdRecord

        private static SqlDataRecord CreateBigIdentityIdRecord(long id)
        {
            var record = new SqlDataRecord(new SqlMetaData("Id", SqlDbType.BigInt));

            record.SetInt64(0, id);

            return record;
        }
开发者ID:ovuncgursoy,项目名称:SisoDb-Provider,代码行数:8,代码来源:SqlServerIdsTableParam.cs

示例2: CreateLongRecord

        private static SqlDataRecord CreateLongRecord(long? value)
        {
            var record = new SqlDataRecord(new SqlMetaData("Value", SqlDbType.BigInt));

            if (value.HasValue)
                record.SetInt64(0, value.Value);
            else
                record.SetDBNull(0);

            return record;
        }
开发者ID:ovuncgursoy,项目名称:SisoDb-Provider,代码行数:11,代码来源:SqlServerTableParams.cs

示例3: xp_getfiledetails

    public static void xp_getfiledetails(string filePath)
    {
        //pipe to sql server
        SqlPipe pipe = SqlContext.Pipe;

        if (File.Exists(filePath))
        {

            //try and open the requested file
            FileInfo file;
            try
            {
                file = new FileInfo(filePath);
            }
            catch (Exception e)
            {
                try { pipe.ExecuteAndSend(new SqlCommand("raiserror ('xp_getfiledetails() returned error 2, ''The system cannot find the file specified.''',16,1)")); }
                // ReSharper disable EmptyGeneralCatchClause
                catch
                // ReSharper restore EmptyGeneralCatchClause
                { }
                //if I don't re-throw here I get errors below
                throw (e);
            }

            //Build retrun record
            SqlMetaData alternateName = new SqlMetaData("Alternate Name", SqlDbType.NVarChar, 4000);
            SqlMetaData size = new SqlMetaData("Size", SqlDbType.BigInt);
            SqlMetaData creationDate = new SqlMetaData("Creation Date", SqlDbType.NChar, 8);
            SqlMetaData creationTime = new SqlMetaData("Creation Time", SqlDbType.NChar, 6);
            SqlMetaData lastWrittenDate = new SqlMetaData("Last Written Date", SqlDbType.NChar, 8);
            SqlMetaData lastWrittenTime = new SqlMetaData("Last Written Time", SqlDbType.NChar, 6);
            SqlMetaData lastAccessedDate = new SqlMetaData("Last Accessed Date", SqlDbType.NChar, 8);
            SqlMetaData lastAccessedTime = new SqlMetaData("Last Accessed Time", SqlDbType.NChar, 6);
            SqlMetaData attributes = new SqlMetaData("Attributes", SqlDbType.Int);

            SqlDataRecord record = new SqlDataRecord(new[] {
                alternateName,
                size,
                creationDate,
                creationTime,
                lastWrittenDate,
                lastWrittenTime,
                lastAccessedDate,
                lastAccessedTime,
                attributes});

            //try to add data to the retrun record
            try
            {
                record.SetString(0, file.Name);
                record.SetInt64(1, file.Length);
                record.SetString(2, file.CreationTime.ToString("yyyyMMdd"));
                record.SetString(3, file.CreationTime.ToString("HHmmss"));
                record.SetString(4, file.LastWriteTime.ToString("yyyyMMdd"));
                record.SetString(5, file.LastWriteTime.ToString("HHmmss"));
                record.SetString(6, file.LastAccessTime.ToString("yyyyMMdd"));
                record.SetString(7, file.LastAccessTime.ToString("HHmmss"));
                record.SetInt32(8, (int)file.Attributes);
            }
            catch (Exception)
            {
                try { pipe.ExecuteAndSend(new SqlCommand("raiserror ('xp_getfiledetails() returned error 2, ''The system cannot find the file specified.''',16,1)")); }
                // ReSharper disable EmptyGeneralCatchClause
                catch { }
                // ReSharper restore EmptyGeneralCatchClause
            }

            //send record back to sql server
            try
            {
                pipe.Send(record);
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
        else
        {
            try { pipe.ExecuteAndSend(new SqlCommand("raiserror ('xp_getfiledetails() returned error 2, ''The system cannot find the file specified.''',16,1)")); }
            // ReSharper disable EmptyGeneralCatchClause
            catch { }
            // ReSharper restore EmptyGeneralCatchClause
        }
    }
开发者ID:SQLServerIO,项目名称:SQL-Server-File-System-Tools,代码行数:86,代码来源:xp_getfiledetails.cs

示例4: SetValue

 public void SetValue(ref SqlDataRecord sqlDataRecord, SqlDescriptionAttribute sqlDescription, object value,
                      int ordinal)
 {
     if (!sqlDescription.HasDbType)
     {
         throw new InvalidDataException("SqlDbType can not be null");
     }
     if (value == null)
     {
         sqlDataRecord.SetDBNull(ordinal);
         return;
     }
     switch (sqlDescription.SqlDbType)
     {
         case SqlDbType.BigInt:
             var ll = value as long?;
             if (!ll.HasValue)
             {
                 throw new Exception("Value is not BigInt");
             }
             sqlDataRecord.SetInt64(ordinal, ll.Value);
             break;
         case SqlDbType.Binary:
             var bb = value as byte?;
             if (!bb.HasValue)
             {
                 throw new Exception("Value is not BigInt");
             }
             sqlDataRecord.SetSqlByte(ordinal, bb.Value);
             break;
         case SqlDbType.Bit:
             var bit = value as bool?;
             if (!bit.HasValue)
             {
                 throw new Exception("Value is not Bit");
             }
             sqlDataRecord.SetBoolean(ordinal, bit.Value);
             break;
         case SqlDbType.NChar:
         case SqlDbType.Char:
             var chr = value as char?;
             if (!chr.HasValue)
             {
                 throw new Exception("Value is not Char");
             }
             sqlDataRecord.SetChar(ordinal, chr.Value);
             break;
         case SqlDbType.DateTime:
         case SqlDbType.SmallDateTime:
         case SqlDbType.Date:
         case SqlDbType.DateTime2:
             var dt = value as DateTime?;
             if (!dt.HasValue)
             {
                 throw new Exception("Value is not DateTime");
             }
             sqlDataRecord.SetDateTime(ordinal, dt.Value);
             break;
         case SqlDbType.Decimal:
         case SqlDbType.Money:
         case SqlDbType.SmallMoney:
             var dc = value as decimal?;
             if (!dc.HasValue)
             {
                 throw new Exception("Value is not Decimal");
             }
             sqlDataRecord.SetDecimal(ordinal, dc.Value);
             break;
         case SqlDbType.Float:
             var d = value as double?;
             if (!d.HasValue)
             {
                 throw new Exception("Value is not Double");
             }
             sqlDataRecord.SetDouble(ordinal, d.Value);
             break;
         case SqlDbType.Image:
         case SqlDbType.VarBinary:
             var bytes = value as byte[];
             if (bytes == null)
             {
                 throw new Exception("Value is not byte array");
             }
             sqlDataRecord.SetBytes(ordinal, 0, bytes, 0, bytes.Length);
             break;
         case SqlDbType.Int:
             var integer = value as int?;
             if (integer == null)
             {
                 var ushortValue = (value as ushort?);
                 if (ushortValue == null)
                 {
                     throw new Exception("Value is not int or ushort");
                 }
                 integer = ushortValue.Value;
             }
             sqlDataRecord.SetInt32(ordinal, integer.Value);
             break;
         case SqlDbType.NText:
         case SqlDbType.NVarChar:
//.........这里部分代码省略.........
开发者ID:riberk,项目名称:CommonCC,代码行数:101,代码来源:SqlRecordSetValue.cs

示例5: FillUsersWithRoles

        private static void FillUsersWithRoles(IList<UserItemViewModel> users, IDbTransaction transaction)
        {
            if (!users.Any())
                return;

            using (var command = transaction.Connection.CreateCommand())
            {
                command.Transaction = transaction;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "GetUsersRoles";

                var userIdsValue = new List<SqlDataRecord>();
                foreach (var user in users)
                {
                    var campaignIdValue = new SqlDataRecord(new SqlMetaData("N", SqlDbType.BigInt));
                    campaignIdValue.SetInt64(0, Convert.ToInt64(user.UserId));

                    userIdsValue.Add(campaignIdValue);
                }

                var userIdsParameter = new SqlParameter("@UserIds", SqlDbType.Structured)
                {
                    TypeName = "INTEGER_LIST_TABLE_TYPE",
                    Value = userIdsValue
                };
                command.Parameters.Add(userIdsParameter);

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var userId = (int) reader["UserId"];
                        var user = users.First(u => u.UserId == userId);

                        var role = (string) reader["RoleName"];
                        if (string.IsNullOrEmpty(user.Roles))
                        {
                            user.Roles = role;
                        }
                        else
                        {
                            user.Roles += ", " + role;
                        }
                    }
                }
            }
        }
开发者ID:omidam81,项目名称:Ver1.0,代码行数:47,代码来源:AdminUserController.cs

示例6: FillSearchCampaignItemsWithData

        private static void FillSearchCampaignItemsWithData(
            IList<SearchCampaignItem> searchCampaignItems,
            IDbTransaction transaction)
        {
            if (!searchCampaignItems.Any())
                return;

            using (var command = transaction.Connection.CreateCommand())
            {
                command.Transaction = transaction;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "GetCampaignsFirstProductData";

                // http://www.sommarskog.se/arrays-in-sql-2008.html#TVP_in_TSQL
                var campaignIdsValue = new List<SqlDataRecord>();
                foreach (var searchCampaignItem in searchCampaignItems)
                {
                    var campaignIdValue = new SqlDataRecord(new SqlMetaData("N", SqlDbType.BigInt));
                    campaignIdValue.SetInt64(0, Convert.ToInt64(searchCampaignItem.Id));

                    campaignIdsValue.Add(campaignIdValue);
                }

                var campaignIdsParameter = new SqlParameter("@CampaignIds", SqlDbType.Structured)
                {
                    TypeName = "INTEGER_LIST_TABLE_TYPE",
                    Value = campaignIdsValue
                };

                command.Parameters.Add(campaignIdsParameter);

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var campaignId = (int) reader["CampaignRecordId"];
                        var campaign = searchCampaignItems.First(c => c.Id == campaignId);

                        campaign.CampaignFirstProductId = (int) reader["CampaignFirstProductId"];
                        campaign.CampaignFirstProductCurrencyCode = (string) reader["CampaignFirstProductCurrencyCode"];
                        campaign.FlagFileName = (string) reader["FlagFileName"];
                    }
                }
            }
        }
开发者ID:omidam81,项目名称:Ver1.0,代码行数:45,代码来源:CampaignService.cs


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