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 7913179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:46:57+00:00 2026-06-03T13:46:57+00:00

SqlException: The conversion of a datetime2 data type to a datetime data type resulted

  • 0

SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.

my code is like this:

        using (var contxt = new realtydbEntities())
        {
            var status = GetStatus();

            var repIssue = new RepairIssue()
            {
                CreaterId = AuthorId,
                RepairItemDesc = this.txtDescription.Text,
                CreateDate = DateTime.Now,//here's the problem
                RepairIssueStatu = status
            };

            contxt.AddObject("RepairIssues", repIssue);
            contxt.SaveChanges();
        }

the CreateDate property mapping to a column which type is smalldatetime.

how to make this code run?

  • 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-03T13:46:58+00:00Added an answer on June 3, 2026 at 1:46 pm

    The root of your problem is that the C# DateTime object is “bigger” than SQL’s smalldatetime type. Here’s a good overview of the differences: http://karaszi.com/the-ultimate-guide-to-the-datetime-datatypes

    So really your options are:

    1. Change the column type from smalldatetime to datetime (or datetime2)
    2. Instead of using EF, construct your own SQL Command (and you can use SqlDateTime)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting this error: System.Data.SqlClient.SqlException : The conversion of a datetime2 data type to a
I´ve got this in a INSERT statment to MSSQL 2008 System.Data.SqlClient.SqlException: The conversion of
I'm changing old, vulnerable SqlCommands with SqlParameters but get a SqlException: System.Data.SqlClient.SqlException {Conversion failed
I am getting the error Exception occurred in NLog ---> System.Data.SqlClient.SqlException: Conversion failed when
I am currently getting this error: System.Data.SqlClient.SqlException: New transaction is not allowed because there
this code gives Incorrectly set or registered parameter SQLException. Can anyone help please? OracleConnection
I'm getting this exception: com.ibm.db2.jcc.c.SqlException: The syntax of the string representation of a datetime
I have an exception handler for the type SqlException and I'm looking at the
I'm using the following setup: public MySQLProcessWriter(Connection con) throws SQLException { String returnNames[] =
I am having this error in my j2ee web application. java.sql.SQLException: ORA-00604: error occurred

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.