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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Select query from datetime field [modified]

Select query from datetime field [modified]

Scheduled Pinned Locked Moved ASP.NET
databasecsharpsql-serverlinqsysadmin
17 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.
  • T treuveni

    Hi, I'm trying to create select query (with LINQ) that's checking if a row is already exists in a table (SQL SERVER). this is the query: var query = from p in dc.OnLineDuties where p.StartDate == start p.EndTime == end select p; return query.ToList(); the tamplate is - "yyyy-mm-dd hh:mm:ss" But i'm not getting any result. Here are the values from the DB: StartDate 2010-11-01 09:00:00.000 EndDate 2010-11-01 10:00:00.000 What i'm doing wrong??? Please assist...

    modified on Sunday, November 7, 2010 6:28 AM

    N Offline
    N Offline
    Not Active
    wrote on last edited by
    #2

    You most likely want to check the dates between the start and end dates, not checking for an exact match as you are doing.


    I know the language. I've read a book. - _Madmatt

    T 1 Reply Last reply
    0
    • T treuveni

      Hi, I'm trying to create select query (with LINQ) that's checking if a row is already exists in a table (SQL SERVER). this is the query: var query = from p in dc.OnLineDuties where p.StartDate == start p.EndTime == end select p; return query.ToList(); the tamplate is - "yyyy-mm-dd hh:mm:ss" But i'm not getting any result. Here are the values from the DB: StartDate 2010-11-01 09:00:00.000 EndDate 2010-11-01 10:00:00.000 What i'm doing wrong??? Please assist...

      modified on Sunday, November 7, 2010 6:28 AM

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

      treuveni wrote:

      p.EndTime

      :confused:

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      T 1 Reply Last reply
      0
      • N Not Active

        You most likely want to check the dates between the start and end dates, not checking for an exact match as you are doing.


        I know the language. I've read a book. - _Madmatt

        T Offline
        T Offline
        treuveni
        wrote on last edited by
        #4

        Mark Nischalke wrote:

        You most likely want to check the dates between the start and end dates, not checking for an exact match as you are doing.

        No, i want to check if the specific date is already in the DB, if not - then i'll insert the row.

        N 1 Reply Last reply
        0
        • L Luc Pattyn

          treuveni wrote:

          p.EndTime

          :confused:

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          T Offline
          T Offline
          treuveni
          wrote on last edited by
          #5

          Luc Pattyn wrote:

          p.EndTime

          I wrote it with LINQ, not with ADO.NET

          L 1 Reply Last reply
          0
          • T treuveni

            Luc Pattyn wrote:

            p.EndTime

            I wrote it with LINQ, not with ADO.NET

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

            treuveni wrote:

            I wrote it with LINQ, not with ADO.NET

            So? I see StartDate and EndTime. Is that what you intend? :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            T 1 Reply Last reply
            0
            • L Luc Pattyn

              treuveni wrote:

              I wrote it with LINQ, not with ADO.NET

              So? I see StartDate and EndTime. Is that what you intend? :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              T Offline
              T Offline
              treuveni
              wrote on last edited by
              #7

              Yes, i made a mistake at the column name when i created the DB, it's not the point here. :)

              1 Reply Last reply
              0
              • T treuveni

                Hi, I'm trying to create select query (with LINQ) that's checking if a row is already exists in a table (SQL SERVER). this is the query: var query = from p in dc.OnLineDuties where p.StartDate == start p.EndTime == end select p; return query.ToList(); the tamplate is - "yyyy-mm-dd hh:mm:ss" But i'm not getting any result. Here are the values from the DB: StartDate 2010-11-01 09:00:00.000 EndDate 2010-11-01 10:00:00.000 What i'm doing wrong??? Please assist...

                modified on Sunday, November 7, 2010 6:28 AM

                P Offline
                P Offline
                phil o
                wrote on last edited by
                #8

                I guess there's a mistake in the formulation of your Linq query. This should be :

                var query = from p in dc.OnLineDuties
                where p.StartDate == start && p.EndTime == end
                select p;

                T 1 Reply Last reply
                0
                • T treuveni

                  Mark Nischalke wrote:

                  You most likely want to check the dates between the start and end dates, not checking for an exact match as you are doing.

                  No, i want to check if the specific date is already in the DB, if not - then i'll insert the row.

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #9

                  In your DB you have StartDate and EndDate. Where is p.EndTime coming from? What is end? Is it a string, a datetime? ??


                  I know the language. I've read a book. - _Madmatt

                  1 Reply Last reply
                  0
                  • P phil o

                    I guess there's a mistake in the formulation of your Linq query. This should be :

                    var query = from p in dc.OnLineDuties
                    where p.StartDate == start && p.EndTime == end
                    select p;

                    T Offline
                    T Offline
                    treuveni
                    wrote on last edited by
                    #10

                    Nop, it's dosen't works. I'm still getting 0 row results from the query. :(

                    R 1 Reply Last reply
                    0
                    • T treuveni

                      Nop, it's dosen't works. I'm still getting 0 row results from the query. :(

                      R Offline
                      R Offline
                      Rhys Gravell
                      wrote on last edited by
                      #11

                      Are you sure such a row exists?

                      Rhys "With no power comes no responsibility"

                      T 1 Reply Last reply
                      0
                      • R Rhys Gravell

                        Are you sure such a row exists?

                        Rhys "With no power comes no responsibility"

                        T Offline
                        T Offline
                        treuveni
                        wrote on last edited by
                        #12

                        goblinTech wrote:

                        Are you sure such a row exists?

                        Sure. Here are the two rows from my DB:

                        DutyId PersonId StartDate EndTime
                        124 37 2010-11-01 09:00:00 2010-11-01 10:00:00
                        152 37 2010-09-01 19:00:00 2010-09-01 22:00:00

                        and still, this query dosen't return any results.

                        modified on Tuesday, November 9, 2010 1:53 AM

                        T 1 Reply Last reply
                        0
                        • T treuveni

                          goblinTech wrote:

                          Are you sure such a row exists?

                          Sure. Here are the two rows from my DB:

                          DutyId PersonId StartDate EndTime
                          124 37 2010-11-01 09:00:00 2010-11-01 10:00:00
                          152 37 2010-09-01 19:00:00 2010-09-01 22:00:00

                          and still, this query dosen't return any results.

                          modified on Tuesday, November 9, 2010 1:53 AM

                          T Offline
                          T Offline
                          treuveni
                          wrote on last edited by
                          #13

                          Can some-one please help me why my query doesn't works? var query = from p in dc.OnLineDuties where p.StartDate == start p.EndTime == end select p; Here are the two rows from my DB: DutyId PersonId StartDate EndTime 124 37 2010-11-01 09:00:00 2010-11-01 10:00:00 152 37 2010-09-01 19:00:00 2010-09-01 22:00:00

                          R 1 Reply Last reply
                          0
                          • T treuveni

                            Can some-one please help me why my query doesn't works? var query = from p in dc.OnLineDuties where p.StartDate == start p.EndTime == end select p; Here are the two rows from my DB: DutyId PersonId StartDate EndTime 124 37 2010-11-01 09:00:00 2010-11-01 10:00:00 152 37 2010-09-01 19:00:00 2010-09-01 22:00:00

                            R Offline
                            R Offline
                            Rhys Gravell
                            wrote on last edited by
                            #14

                            To expand on something Mark Nischalke asked some time ago to which you never replied, what is start, what is end? Are they string's, are they datetime's, what are there values at runtime?

                            Rhys "With no power comes no responsibility"

                            T 1 Reply Last reply
                            0
                            • R Rhys Gravell

                              To expand on something Mark Nischalke asked some time ago to which you never replied, what is start, what is end? Are they string's, are they datetime's, what are there values at runtime?

                              Rhys "With no power comes no responsibility"

                              T Offline
                              T Offline
                              treuveni
                              wrote on last edited by
                              #15

                              goblinTech wrote:

                              what is start, what is end?

                              they are DateTime's.

                              goblinTech wrote:

                              what are there values at runtime?

                              the user inserts the value trough text box and i parse it to a DateTime type. at the end the become dd/MM/yyyy hh:mm:ss formt. The colums ype is also DateTime. 10x

                              R 1 Reply Last reply
                              0
                              • T treuveni

                                goblinTech wrote:

                                what is start, what is end?

                                they are DateTime's.

                                goblinTech wrote:

                                what are there values at runtime?

                                the user inserts the value trough text box and i parse it to a DateTime type. at the end the become dd/MM/yyyy hh:mm:ss formt. The colums ype is also DateTime. 10x

                                R Offline
                                R Offline
                                Rhys Gravell
                                wrote on last edited by
                                #16

                                But what are the values of start and end at runtime? Can you debug and check?

                                Rhys "With no power comes no responsibility"

                                T 1 Reply Last reply
                                0
                                • R Rhys Gravell

                                  But what are the values of start and end at runtime? Can you debug and check?

                                  Rhys "With no power comes no responsibility"

                                  T Offline
                                  T Offline
                                  treuveni
                                  wrote on last edited by
                                  #17

                                  The values are: StartDate - 2010-11-01 09:00:00 EndTime - 2010-11-01 10:00:00 same like in the DB

                                  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