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


C# SqlDataReader.GetValueOrDefault方法代码示例

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


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

示例1: FillComment

        private Comment FillComment(SqlDataReader reader)
        {
            var comment = new Comment();
            comment.Id = reader.GetInt32(0);
            comment.PostId = reader.GetInt32(1);
            comment.Name = reader.GetString(2);
            comment.Email = reader.GetValueOrDefault<string>(3);
            comment.Url = reader.GetValueOrDefault<string>(4);
            comment.Body = reader.GetString(5);
            comment.Status = (CommentStatus)reader.GetInt32(6);
            comment.DateCreated = reader.GetDateTime(7);

            return comment;
        }
开发者ID:jordiruiz,项目名称:Joomiz.Blog,代码行数:14,代码来源:CommentRepository.cs

示例2: FillPost

        private Post FillPost(SqlDataReader reader)
        {
            var post = new Post();

            post.Id = reader.GetInt32(0);
            post.Author = new Author();
            post.Author.Id = reader.GetInt32(1);
            post.Title = reader.GetValueOrDefault<string>(2);
            post.Body = reader.GetValueOrDefault<string>(3);
            post.IsPublished = reader.GetBoolean(4);
            post.DateCreated = reader.GetDateTime(5);

            return post;
        }
开发者ID:jordiruiz,项目名称:Joomiz.Blog,代码行数:14,代码来源:PostRepository.cs

示例3: ConvertReaderDataToScheduleItemList

        private static ScheduleItemList ConvertReaderDataToScheduleItemList(SqlDataReader reader)
        {
            ScheduleItemList schedules = null;

            if (reader.HasRows)
            {
                schedules = new ScheduleItemList();
                while (reader.Read())
                {
                    schedules.Add(new ScheduleItem(reader.GetValueOrDefault<int>("ID"),
                                                    reader.GetValueOrDefault<int>("ProjectID"),
                                                    reader.GetValueOrDefault<int>("EmployeeID"),
                                                    reader.GetValueOrDefault<int>("WeekID"),
                                                    reader.GetValueOrDefault<decimal>("Hours")));
                }
            }

            return schedules;
        }
开发者ID:jbob24,项目名称:KPFF,代码行数:19,代码来源:ScheduleData.cs

示例4: ConvertReaderDataToProjectList

        private static ProjectList ConvertReaderDataToProjectList(SqlDataReader reader)
        {
            ProjectList projects = null;

            if (reader.HasRows)
            {
                projects = new ProjectList();
                while (reader.Read())
                {
                    var project = new Project();

                    project.Id = reader.GetValueOrDefault<int>("ID");
                    project.ProjectNumber = reader.GetValueOrDefault<decimal>("ProjectNo");
                    project.Name = reader.GetValueOrDefault<string>("ProjectName");
                    project.ClientId = reader.GetValueOrDefault<int>("ClientID");
                    project.StatusId = reader.GetValueOrDefault<int>("ProjectStatus");
                    project.Location = reader.GetValueOrDefault<string>("ProjectLocation");
                    project.ConstructionType = reader.GetValueOrDefault<string>("ConstructionType");
                    project.ProjectType = reader.GetValueOrDefault<string>("ProjectType");
                    project.PhaseId = reader.GetValueOrDefault<int>("PhaseID");
                    project.EstimatedStartDate = reader.GetValueOrDefault<DateTime>("EstimatedStartDate");
                    project.EstimatedCompletionDate = reader.GetValueOrDefault<DateTime>("EstimatedCompletionDate");
                    project.FeeAmount = reader.GetValueOrDefault<decimal>("FeeAmount");
                    project.FeeStructure = reader.GetValueOrDefault<string>("FeeStructure");
                    project.ContractTypeId = reader.GetValueOrDefault<int>("ContractType");
                    project.PICId = reader.GetValueOrDefault<int>("PIC");
                    project.PM1Id = reader.GetValueOrDefault<int>("PM1");
                    project.PM2Id = reader.GetValueOrDefault<int>("PM2");
                    project.LastModifiedByUserId = reader.GetValueOrDefault<int>("LastModifiedByUserID");
                    project.PICCode = reader.GetValueOrDefault<string>("PICCode");
                    project.PM1Code = reader.GetValueOrDefault<string>("PM1Code");
                    project.PM2Code = reader.GetValueOrDefault<string>("PM2Code");
                    project.Comments = reader.GetValueOrDefault<string>("Comments");
                    project.IsActive = reader.GetValueOrDefault<bool>("Active");
                    project.LastModifiedDate = reader.GetValueOrDefault<DateTime>("LastModifiedDate");

                    projects.Add(project);
                }
            }

            return projects;
        }
开发者ID:jbob24,项目名称:KPFF,代码行数:42,代码来源:ProjectData.cs

示例5: ConvertReaderDataToProjectList

        private static List<Employee> ConvertReaderDataToProjectList(SqlDataReader reader)
        {
            List<Employee> employees = null;

            if (reader.HasRows)
            {
                employees = new List<Employee>();
                while (reader.Read())
                {
                    var employee = new Employee();

                    employee.Id = reader.GetValueOrDefault<int>("EmployeeID");
                    employee.FirstName = reader.GetValueOrDefault<string>("EmployeeFirst");
                    employee.LastName = reader.GetValueOrDefault<string>("EmployeeLast");
                    employee.Name = reader.GetValueOrDefault<string>("EmployeeName");
                    employee.Title = reader.GetValueOrDefault<string>("Title");
                    employee.StartDate = reader.GetValueOrDefault<DateTime>("EmploymentStartDate");

                    int yearsOfExperience = 0;
                    int.TryParse(reader.GetValueOrDefault<string>("YearsOfExperience"), out yearsOfExperience);
                    employee.YearsOfExperience = yearsOfExperience;

                    employee.Education = reader.GetValueOrDefault<string>("Education");
                    employee.Licenses = reader.GetValueOrDefault<string>("Licenses");
                    employee.ProfessionalMemberships = reader.GetValueOrDefault<string>("ProfessionalMemberships");
                    employee.ProfessionalCommittees = reader.GetValueOrDefault<string>("ProfessionalCommittees");
                    employee.Comments = reader.GetValueOrDefault<string>("Comments");
                    employee.HoursPerWeek = reader.GetValueOrDefault<decimal>("HoursPerWeek");
                    employee.PhoneExtension = reader.GetValueOrDefault<int>("PhoneExtension");
                    employee.EmailAddress = reader.GetValueOrDefault<string>("EmailAddress");
                    employee.HasPMFiscalSummaryAddress = reader.GetValueOrDefault<bool>("PMFiscalSummary");
                    employee.HasPICFiscalSummaryAddress = reader.GetValueOrDefault<bool>("PICFiscalSummary");
                    employee.LastModifiedDate = reader.GetValueOrDefault<DateTime>("LastModified");
                    employee.LastModifiedBy = reader.GetValueOrDefault<string>("LastModifiedBy");

                    employees.Add(employee);
                }
            }

            return employees;
        }
开发者ID:jbob24,项目名称:KPFF,代码行数:41,代码来源:EmployeeData.cs


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