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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:26:55+00:00 2026-05-27T23:26:55+00:00

I have a strange problem…I have a MySql db with some columns and one

  • 0

I have a strange problem…I have a MySql db with some columns and one of the column is date_purchased which is of type date_time.

I am using C# and made a DatetimePicker and user selects a date.

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
    {

        varDate = dateTimePicker1.Value;

    }

Now the problem is I have to compare the two datetimes (one from the database and one from the User) and I should display the records that are less than the date selected by the user(varDate).

select * from orders where date_purchased < = '" + varDate + "'";

I am executing this query but i am getting an exception

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '12/25/2011 8:01:31 PM'' at line 1

I wrote the connection string and all and I am struck at the query.
Any Help will be much appreciated…
Thanks,
Subash

  • 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-27T23:26:56+00:00Added an answer on May 27, 2026 at 11:26 pm

    You have not given any details on what you are using to run the select query; however, if you are using the connector provided by Mysql (Connector/Net) then you should be using parameters. Which would look something like this:

    String sql = "select * from orders where date_purchased < @DatePurchased";
    
    MySqlDataAdapter adapter = new MySqlDataAdapter(sql, connection);
    adapter.SelectCommand.Parameters.Add("DatePurchased", MySqlType.DateTime).Value = varDate; 
    adapter.Fill(dataSet);   
    

    Using parameters will ensure the values are converted and will also prevent SQL Injections

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

Sidebar

Related Questions

I have a strange problem with a DataGridView I'm using which is bound to
We have very strange problem, one of our applications is continually querying server by
I have a strange problem with lxml when using the deployed version of my
I have a strange problem with some documents on my webpage. My data is
I have a strange problem with a memory leak (the only one ;-) )
I have some strange problem with table in Firefox. What I want to create
I have a strange problem. I have a jQuery document.ready function executing some script
I have a strange problem when deleteting records using linq, my suspicion is that
I have a strange problem: I have a site which has an administration system.
I have some strange problem with PIL not resizing the image. from PIL import

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.