Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Convert problem!

Convert problem!

Scheduled Pinned Locked Moved C#
questionhelp
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    miss YY
    wrote on last edited by
    #1

    int mm =int.Parse(dateTimePicker1.Value.ToString("dd")); int nn =int.Parse(dateTimePicker1.Value.ToString("dd")); SqlCommand SCD = new SqlCommand("select * from table_inf where time>=mm and time<=nn", Conn); i use data Sql2000,Field time's Property is datetime what's wrong with it? how can i change it thank you everyone!!

    L D N 3 Replies Last reply
    0
    • M miss YY

      int mm =int.Parse(dateTimePicker1.Value.ToString("dd")); int nn =int.Parse(dateTimePicker1.Value.ToString("dd")); SqlCommand SCD = new SqlCommand("select * from table_inf where time>=mm and time<=nn", Conn); i use data Sql2000,Field time's Property is datetime what's wrong with it? how can i change it thank you everyone!!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      you only get questions now,l for you to answer and deduce reasonable conclusions yourself: what is the difference between mm and nn??? what type is dateTimePicker1.Value? why would you turn it into a string and then parse that string? that type has a lot of interesting Properties. Start reading the documentation on that type! and what is the type of your database table's "time" field? are mm and nn in your SQL of the same type as time? :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      1 Reply Last reply
      0
      • M miss YY

        int mm =int.Parse(dateTimePicker1.Value.ToString("dd")); int nn =int.Parse(dateTimePicker1.Value.ToString("dd")); SqlCommand SCD = new SqlCommand("select * from table_inf where time>=mm and time<=nn", Conn); i use data Sql2000,Field time's Property is datetime what's wrong with it? how can i change it thank you everyone!!

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        miss YY wrote:

        how can i change it

        What are you trying to do here? Both mm and nn variables will have same value and your query may not return any values.

        miss YY wrote:

        i use data Sql2000,Field time's Property is datetime

        Then you need to compare against a DateTime not just an integer variable that has date.

        DateTime mm = dateTimePicker1.Value;
        DateTime nn = dateTimePicker2.Value;
        SqlCommand SCD = new SqlCommand("select * from table_inf where time >= @mm and time <= @nn", Conn);
        SCD.Parameters.AddWithValue("@mm", mm);
        SCD.Parameters.AddWithValue("@nn", nn);

        Best wishes, Navaneeth

        P 1 Reply Last reply
        0
        • M miss YY

          int mm =int.Parse(dateTimePicker1.Value.ToString("dd")); int nn =int.Parse(dateTimePicker1.Value.ToString("dd")); SqlCommand SCD = new SqlCommand("select * from table_inf where time>=mm and time<=nn", Conn); i use data Sql2000,Field time's Property is datetime what's wrong with it? how can i change it thank you everyone!!

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          1. You are comparing a date and integer. Compare dates with dates. You should use your date time picker's value right away. 2. See you select command:

          miss YY wrote:

          select * from table_inf where time>=mm and time<=nn

          Entire thing is a string. How is it supposed to get the values in mm and nn? You should read about SQLParameters class and use it. Also, from the ToString overload you are using, it shows that you are just checking the day part of the date. Do you really want to do that way? If you want to check that way, you should use day(time) instead on time in your SQL and then compare. But be sure that this will ONLY compare the day part and not the month and year. Edit: Missed what Luc spotted. Both mm and nn will have same values. So, why not just check equality with one value instead of two?

          50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

          modified on Sunday, November 29, 2009 10:29 PM

          1 Reply Last reply
          0
          • N N a v a n e e t h

            miss YY wrote:

            how can i change it

            What are you trying to do here? Both mm and nn variables will have same value and your query may not return any values.

            miss YY wrote:

            i use data Sql2000,Field time's Property is datetime

            Then you need to compare against a DateTime not just an integer variable that has date.

            DateTime mm = dateTimePicker1.Value;
            DateTime nn = dateTimePicker2.Value;
            SqlCommand SCD = new SqlCommand("select * from table_inf where time >= @mm and time <= @nn", Conn);
            SCD.Parameters.AddWithValue("@mm", mm);
            SCD.Parameters.AddWithValue("@nn", nn);

            Best wishes, Navaneeth

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Yes, but why use local variables at all?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups