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

  • SEARCH
  • Home
  • 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 6628351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:07:16+00:00 2026-05-25T22:07:16+00:00

i am trying to make INSERT command to my SQLEXPRESS db and recieve error

  • 0

i am trying to make INSERT command to my SQLEXPRESS db
and recieve error while trying to enter a value to my DateTime column.

this is the sql command i use:

SqlDateTime sTime = new SqlDateTime(book.PublishedDate);                

string sql = string.Format("Insert into Books" +
"(Name, PublishDate, IsInternal) Values" +
"('{0}', '{1}', '{2}')",
book.Name, sTime.Value, book.IsInternal);

book.PublishedDate – is DateTime type
and the PublishedDate column is sql DateTime

i recieve the following error:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

how can i resolve that ?

  • 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-05-25T22:07:16+00:00Added an answer on May 25, 2026 at 10:07 pm

    Use parametrised queries. They’re supported in practically any data access technology you might be using. And they allow you to keep treating dates as dates, instead of converting everything into strings.

    E.g. (ADO.Net SqlCommand)

    SqlCommand cmd = new SqlCommand("Insert into Books (Name,PublishDate,IsInternal) Values (@Name,@PublishDate,@IsInternal)");
    cmd.Parameters.Add(new SqlParameter("@Name", System.Data.SqlDbType.VarChar, 50));
    cmd.Parameters.Add(new SqlParameter("@PublishDate", System.Data.SqlDbType.DateTime));
    cmd.Parameters.Add(new SqlParameter("@IsInternal", System.Data.SqlDbType.Bit));
    
    cmd.Parameters["@Name"].Value = book.Name;
    cmd.Parameters["@PublishDate"].Value = book.PublishedDate;
    cmd.Parameters["@IsInternal"].Value = book.IsInternal;
    

    The single largest source of errors people make when they report datatype issues between their client code and an SQL database is where, for whatever reason, they’ve converted everything to strings. Not only is this usually less efficient, but you’re also relying on at least two conversions to happen correctly in between (Type -> string and string -> Type), and frequently at least one of those conversions will be left to whatever the default conversion function(s) are.

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

Sidebar

Related Questions

I'm trying to make a yasnippet with this function \cite{${1:label$(unless yas/modified-p (reftex-citation nil 'dont-insert))}}$0
im trying to make an insert to my Database and im receiving an error,
I'm trying to make an ajax call to grab session data to insert into
I'm using folding-mode in emacs and was trying to make a function to insert
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to make a generic PL/SQL procedure to export data in specific XML format,
While trying to make one of my python applications a bit more robust in
Hey, I am new to Oracle SQL and I am trying to make a
I'm trying to make a script that would insert img element after each link
Im trying to make dynamic column list that will be 4 columns total (PHP).

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.