Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8952639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:55:08+00:00 2026-06-15T13:55:08+00:00

I have this line in my sql server 2008 r2 database, but I don’t

  • 0

I have this line in my sql server 2008 r2 database, but I don’t understand:

2012-12-06 11:00:36.703 and is of type DATETIME

When I display it in my view it is:

Mon, Jan 1, 0001 

Here my code:

var allNews = ZincService.NewsService.GetNewsPostsForId(id);

List<Zinc.Web.Areas.News.ViewModels.Home.NewsPostsViewModel> newsItems = new List<NewsPostsViewModel>();

foreach (var newsItem in allNews)
{ 
  NewsPostsViewModel newsItemViewModel = new NewsPostsViewModel();
  newsItemViewModel.CommentDate = String.Format("{0:ddd, MMM d, yyyy}", newsItem.CommentDate);
}

public class NewsPostsViewModel
{
  public Entities.News.News MainNews { get; set; }
  public virtual string News { get; set; }
  public virtual int NewsId { get; set; }
  public virtual string CommentDate { get; set; }
}

  public List<DataModels.News.NewsPostsDataModel> GetNewsPostsForId(int id)
{
  using (SqlConnection conn = new SqlConnection(ZincModelContainer.CONNECTIONSTRING))
  {
    using (SqlCommand cmd = conn.CreateCommand())
    {
      conn.Open();
      cmd.CommandType = System.Data.CommandType.StoredProcedure;
      cmd.CommandText = "[News].[GetNewsPostsForId]";

      SqlParameter param = new SqlParameter("@Id", System.Data.SqlDbType.Int);
      param.Value = id;
      cmd.Parameters.Add(param);

      List<DataModels.News.NewsPostsDataModel> news = new List<DataModels.News.NewsPostsDataModel>();

      using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
      {
        DataTable dt = new DataTable();
        adapter.Fill(dt);

        foreach (DataRow row in dt.Rows)
        {
          string message = Convert.ToString(row["NewsDescription"]);
          news.Add(new DataModels.News.NewsPostsDataModel { NewsPostId = id ,Message = message});
        }
      }

      return news;
    }
  }
}

public class NewsPostsDataModel
{
  public virtual int NewsPostId { get; set; }
  public virtual string Message { get; set; }
  public virtual DateTime CommentDate { get; set; }
}

Can some one help me, please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:55:09+00:00Added an answer on June 15, 2026 at 1:55 pm

    This is the problem:

    news.Add(new DataModels.News.NewsPostsDataModel { NewsPostId = id ,Message = message});
    

    You’re not populating CommentDate here, so it’s got the default value of DateTime.MinValue.

    Of course we now can’t tell whether your stored procedure returns the value at all, but assuming it does, you should presumably be fetching it from the DataRow and putting it in your model…

    Before you just fix the code, you should take a step back and think about your diagnostic process. Did you try debugging into this? Adding logging? You should have been able to see very quickly that you didn’t have a CommentDate in the model, and then tried to work out why you didn’t have a CommentDate, which should have led you back to the code creating the instance of the model. If you can improve your diagnostic processes, you can speed you your future development significantly by not having to ask as many questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this line of code in SQL server 2008 R2 select * from
I have a column(named MetaData) of type 'xml' in my sql server 2008 database.
I have a SQL Server 2008 GEOGRAPHY data type in my database containing a
So I have a sql server 2008 database with 9 tables in them, they
I have a database sitting on a SQL Server 2008 with ~12 billion rows
I have a database that I am viewing with SQL Server Management Studio 2008
I have a T-SQL stored procedure in a SQL Server 2008 database that I
I have simple SQL Server 2008 table that has a column ourdate of type
I have a working database application using WPF and SQL Server 2008 R2, which
I have a SQL Server 2008 database, with a column named ES&D . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.