本文整理汇总了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);
}
}
示例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);
}
}