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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:37:53+00:00 2026-06-11T08:37:53+00:00

The code below Works ok; from 01st to 12th of every month; However as

  • 0

The code below Works ok; from 01st to 12th of every month; However as soon as I click on 13th or greater date I Get this error

Conversion failed when converting date and/or time from character string.

This my Code

 DateTime dt = Convert.ToDateTime(Calendar1.SelectedDate.ToString("yyyy-MM-dd"));

    myConnection.Open();
    string cmdStr1 = "SELECT COUNT(*) FROM Payment WHERE PaymentDate = '" + dt + "'";
    SqlCommand PIDexist1 = new SqlCommand(cmdStr1, myConnection);
    int temp1 = Convert.ToInt32(PIDexist1.ExecuteScalar().ToString());
    myConnection.Close();

Thank for your Help

This is How Date is saved in my Database 2012-01-13

  • 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-11T08:37:54+00:00Added an answer on June 11, 2026 at 8:37 am

    No, never bind dates like that. Let the .NET data provider handle this for you – there are just way too many pitfalls with locales on the App and Sql Server for you to use strings as dates.

    myConnection.Open();
    string cmdStr1 = "SELECT COUNT(*) FROM Payment WHERE PaymentDate = @dt'";
    SqlCommand PIDexist1 = new SqlCommand(cmdStr1, myConnection);
    SqlParameter parameter = PIDexist1.Parameters.Add("@dt", System.Data.SqlDbType.DateTime);
    parameter.Value = dt;
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is the code from a plugin for Joomla. It works on it's own
HI all, Below mentioned javascript code works fine in all browsers including chrome(from second
The code below works well right now; however, it's serially executed. I'd like to
The code below works (it will eventually pull records from a database via SQL),
The code below works perfectly fine with Firefox, however, I am having problems with
The code below works perfect for binding actual urls grabbed from the net. My
I was hoping I could get some help from you guys. The code below
I'm creating word documents from templates (.dot) via Microsoft.Office.Interop.Word . The code below works
I sending a message with this code below and works: $headers = 'From: Online
The code below works well but grabs only the UIView which is VISIBLE on

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.