data type mismatch between vb date datatype and ms access datetime data type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GR M
    New Member
    • Dec 2010
    • 19

    data type mismatch between vb date datatype and ms access datetime data type

    I'v designed a ms access database table with one field having Datetime datatype. I can Insert data into it from vb.net front end by using
    Code:
    trns_dt = DateTime.Now.Date
    .
    But when I fetch records from the tableand assign the dataset datasource as da, it shows datatype mismatch error.
    Code:
     
    da = New OleDbDataAdapter("Select * from Daily_Transaction where trans_date between '" & dtp_from_dt.value & "' and '" & dtp_To.value & "' ", con)
    ds = New DataSet
                    ds.Clear()
                    da.Fill(ds, "Daily_Transaction")
                    DGV_Admin.DataSource = ds.Tables(0)
                    DGV_Admin.Show()
    Plz help ASAP
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. In line 2 you are treating the dates as text by enclosing them in quotes, which I think is the source of your type mismatch. The Access query engine uses the pound sign (#) as a delimiter for dates, so line 2 should be rewritten as:

    Code:
    da = New OleDbDataAdapter("Select * from Daily_Transaction where trans_date between #" & dtp_from_dt.value & "# and #" & dtp_To.value & "# ", con)
    Please note that for comparisons such as BETWEEN to work consistently date values presented as literals need to be in ANSI standard format - that is, month-first as mm/dd/yyyy.

    -Stewart

    Comment

    • GR M
      New Member
      • Dec 2010
      • 19

      #3
      Thanks A lot sir.

      Comment

      Working...