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. How to retrieve the data by Date/Time Data Type from a Table ?

How to retrieve the data by Date/Time Data Type from a Table ?

Scheduled Pinned Locked Moved Visual Basic
databasehelptutorialquestioncareer
2 Posts 2 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.
  • P Offline
    P Offline
    phowarso
    wrote on last edited by
    #1

    My table has 4 fields that Name, Age, Date and Town. Data can add and delete. Data from Date field are displayed onto the ComboBox by DISTINCT SQL keyword. I wanna retrieve the data from Name, Age and Town by choosing a data from ComboBox that contains date data. I will display my data onto a DataGridView. When I run my project no data display noto the DataGridView. But I get for 18/3/08, error format 12:00:00AM is displayed in Message box and for other date I get correct format. My code is following... Private Sub cbbDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbbDate.SelectedIndexChanged On Error Resume Next Dim dt As Date cbbDate.Text = cbbDate.SelectedItem If Not cbbDate.Text = "All Date" Then dt = CDate(cbbDate.SelectedItem).ToString("M,d,yyyy") MsgBox(dt) DisplayReport("SELECT * FROM tblSave WHERE Date=" & dt & " ORDER BY Name ASC") Else ShowAll() End If Date Field Format in the table is 'Short Date'. ( month, day, year) Date format from ComboBox is ( day, month, year).

    C 1 Reply Last reply
    0
    • P phowarso

      My table has 4 fields that Name, Age, Date and Town. Data can add and delete. Data from Date field are displayed onto the ComboBox by DISTINCT SQL keyword. I wanna retrieve the data from Name, Age and Town by choosing a data from ComboBox that contains date data. I will display my data onto a DataGridView. When I run my project no data display noto the DataGridView. But I get for 18/3/08, error format 12:00:00AM is displayed in Message box and for other date I get correct format. My code is following... Private Sub cbbDate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbbDate.SelectedIndexChanged On Error Resume Next Dim dt As Date cbbDate.Text = cbbDate.SelectedItem If Not cbbDate.Text = "All Date" Then dt = CDate(cbbDate.SelectedItem).ToString("M,d,yyyy") MsgBox(dt) DisplayReport("SELECT * FROM tblSave WHERE Date=" & dt & " ORDER BY Name ASC") Else ShowAll() End If Date Field Format in the table is 'Short Date'. ( month, day, year) Date format from ComboBox is ( day, month, year).

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      phowarso wrote:

      But I get for 18/3/08, error format

      phowarso wrote:

      Date Field Format in the table is 'Short Date'. ( month, day, year) Date format from ComboBox is ( day, month, year).

      Well, that's obviously the issue then.

      phowarso wrote:

      DisplayReport("SELECT * FROM tblSave WHERE Date=" & dt & " ORDER BY Name ASC")

      Don't do this. Parameterise your query, then this sort of thing will take care of itself.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      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