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


C# SqlDataReader.GetInt32Safe方法代码示例

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


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

示例1: LoadArticle

        //public void LoadArticle(int articleId)
        //{
        //    string queryString = "SELECT [ArticleId],[CategoryId],[SecondLevCategoryId],[ThirdLevCategoryId],[Name] " +
        //                                ",[Title],[Description],[Author],[Keywords],[MainContent],[SideContent] " +
        //                                ",[ListItemContent],[ViewRequests],[URLLink] " +
        //                        "FROM [MLB].[dbo].[Article] " +
        //                        "WHERE ArticleId = " + articleId;
        //    using (SqlConnection connection = new SqlConnection(Base.conn))
        //    {
        //        // Create the Command and Parameter objects.
        //        SqlCommand command = new SqlCommand(queryString, connection);
        //        try
        //        {
        //            connection.Open();
        //            SqlDataReader reader = command.ExecuteReader();
        //            LoadArticle(reader);
        //            reader.Close();
        //        }
        //        catch (Exception ex)
        //        {
        //            DIYError sError = new DIYError(ex);
        //        }
        //    }
        //}
        //public void LoadArticle(int categoryId, int categoryLevel)
        //{
        //    string queryString = "SELECT [ArticleId],[CategoryId],[SecondLevCategoryId],[ThirdLevCategoryId],[Name] " +
        //                                ",[Title],[Description],[Author],[Keywords],[MainContent],[SideContent] " +
        //                                ",[ListItemContent],[ViewRequests],[URLLink] " +
        //                        "FROM [MLB].[dbo].[Article] ";
        //    switch (categoryLevel)
        //    {
        //        case 1:
        //            queryString += "WHERE CategoryId = " + categoryId;
        //            break;
        //        case 2:
        //            queryString += "WHERE SecondLevCategoryId = " + categoryId;
        //            break;
        //        case 3:
        //            queryString += "WHERE ThirdCategoryId = " + categoryId;
        //            break;
        //    }
        //    using (SqlConnection connection = new SqlConnection(Base.conn))
        //    {
        //        // Create the Command and Parameter objects.
        //        SqlCommand command = new SqlCommand(queryString, connection);
        //        try
        //        {
        //            connection.Open();
        //            SqlDataReader reader = command.ExecuteReader();
        //            LoadArticle(reader);
        //            reader.Close();
        //        }
        //        catch (Exception ex)
        //        {
        //            DIYError sError = new DIYError(ex);
        //        }
        //    }
        //}
        private void LoadArticle(SqlDataReader reader)
        {
            while (reader.Read())
            {
                this.ArticleId = reader.GetInt32(0);

                this.Name = reader.GetString(1);
                this.Title = reader.GetStringSafe(2);
                this.Description = reader.GetStringSafe(3);
                this.Author = reader.GetStringSafe(4);
                this.Keywords = reader.GetStringSafe(5);
                this.MainContent = reader.GetStringSafe(6);
                this.ViewRequests = reader.GetInt32(7);
                this.URLLink = reader.GetString(8);
                this.NameId = reader.GetString(9);
                this.CategoryRowId = reader.GetInt32(10);
                this.CategoryId = reader.GetInt32Safe(11);
                this.SecondLevCategoryId = reader.GetInt32Safe(12);
                this.ThirdLevCategoryId = reader.GetInt32Safe(13);
                this.CategoryName = reader.GetString(14);
                this.CategoryUrl = reader.GetString(15);
                this.SecondLevCategoryName = reader.GetStringSafe(16);
                this.SecondLevCategoryUrl = reader.GetStringSafe(17);
                this.ThirdLevCategoryName = reader.GetStringSafe(18);
                this.ThirdLevCategoryUrl = reader.GetStringSafe(19);
                this.CreatedDate = reader.GetDateTime(20);
            }
        }
开发者ID:sumdood31,项目名称:DIYFE,代码行数:87,代码来源:Article.cs

示例2: LoadArticle

 private void LoadArticle(SqlDataReader reader)
 {
     while (reader.Read())
     {
         this.ArticleId = reader.GetInt32(0);
         this.CategoryId = reader.GetInt32Safe(1);
         this.SecondLevCategoryId = reader.GetInt32Safe(2);
         this.ThirdLevCategoryId = reader.GetInt32Safe(3);
         this.Name = reader.GetString(4);
         this.Title = reader.GetStringSafe(5);
         this.Description = reader.GetStringSafe(6);
         this.Author = reader.GetStringSafe(7);
         this.Keywords = reader.GetStringSafe(8);
         this.MainContent = reader.GetStringSafe(9);
     }
 }
开发者ID:sumdood31,项目名称:DIYFE,代码行数:16,代码来源:Article.cs


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