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. General Programming
  3. Visual Basic
  4. date vb.net2005 & sqlserver 2005

date vb.net2005 & sqlserver 2005

Scheduled Pinned Locked Moved Visual Basic
databasecsharpsql-serversysadmin
6 Posts 4 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.
  • N Offline
    N Offline
    nilam11
    wrote on last edited by
    #1

    hi guys maskedtextbox1.mask = "##/##/####" mskedtextbox2.mask = "##/##/####" i am using maskedtextbox for getting i/p of date. i have taken mask properties short datetime. my data is stored in sql server 2005 where i have taken data type is varchar(10) in dd/mm/yyyy format (28/08/2007 & 31/08/2007). my problem is that when i execute the sql query for the selected period in maskedtextbox it does not show correct data. e.g. sql_str = "insert mdate into xyz (select mdate from abc where " & _ "mdate between" & " '" &maskedtextbox1.text& "' and '"&mskedtextbox2.text&"'" "and flag= '" & mflag & "')" or using where condition it is not executing correct data. can i get where i am wrong ? if is there any more suggestion for me suggest me.

    Thanks bye

    G 1 Reply Last reply
    0
    • N nilam11

      hi guys maskedtextbox1.mask = "##/##/####" mskedtextbox2.mask = "##/##/####" i am using maskedtextbox for getting i/p of date. i have taken mask properties short datetime. my data is stored in sql server 2005 where i have taken data type is varchar(10) in dd/mm/yyyy format (28/08/2007 & 31/08/2007). my problem is that when i execute the sql query for the selected period in maskedtextbox it does not show correct data. e.g. sql_str = "insert mdate into xyz (select mdate from abc where " & _ "mdate between" & " '" &maskedtextbox1.text& "' and '"&mskedtextbox2.text&"'" "and flag= '" & mflag & "')" or using where condition it is not executing correct data. can i get where i am wrong ? if is there any more suggestion for me suggest me.

      Thanks bye

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      As you are storing the dates as text, you can't do any calcualtions on them (including comparison). You could convert every value to a date in the query, but that's very inefficient. Store the values as dates in the database, not text.

      --- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams

      N 1 Reply Last reply
      0
      • G Guffa

        As you are storing the dates as text, you can't do any calcualtions on them (including comparison). You could convert every value to a date in the query, but that's very inefficient. Store the values as dates in the database, not text.

        --- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams

        N Offline
        N Offline
        nilam11
        wrote on last edited by
        #3

        hi but it is working in vb6. so i think that it is possible in vb.net also. if i use dtpicker then is it possible ?

        Thanks bye

        D 1 Reply Last reply
        0
        • N nilam11

          hi but it is working in vb6. so i think that it is possible in vb.net also. if i use dtpicker then is it possible ?

          Thanks bye

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          VB6 handles date/time differently than VB.NET and SQL Server. Who cares if it "used to work" under VB6 since you're not using it now. You absolutely can NOT store dates in the database as strings and expect to be able to do comparisons and math on those dates, when they are not being treated as dates. Instead, they are treated no differently than if you stored "iwjf948fu04f" as your date. Using a different control will have no effect since you are STILL storing dates as strings and not actualy datetime values in the database.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          S 1 Reply Last reply
          0
          • D Dave Kreskowiak

            VB6 handles date/time differently than VB.NET and SQL Server. Who cares if it "used to work" under VB6 since you're not using it now. You absolutely can NOT store dates in the database as strings and expect to be able to do comparisons and math on those dates, when they are not being treated as dates. Instead, they are treated no differently than if you stored "iwjf948fu04f" as your date. Using a different control will have no effect since you are STILL storing dates as strings and not actualy datetime values in the database.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            S Offline
            S Offline
            Salman Sheikh
            wrote on last edited by
            #5

            Change the data type of database columns to datetime and while storing and changing the values of that field try this statement for dates Date.ParseExact(txtMasked.text,"Format") format means "dd/mm/yyyy" i think it is in your case. the above statement will return a Date object which can be sent to database and then retrieved :)

            Salman Sheikh

            D 1 Reply Last reply
            0
            • S Salman Sheikh

              Change the data type of database columns to datetime and while storing and changing the values of that field try this statement for dates Date.ParseExact(txtMasked.text,"Format") format means "dd/mm/yyyy" i think it is in your case. the above statement will return a Date object which can be sent to database and then retrieved :)

              Salman Sheikh

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              And you're telling me this why?? Yeah, but this doesn't solve the underlying problem of storing dates in the database as strings.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              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