Results 1 to 7 of 7

Thread: whts wrong with the sql statement [resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2004
    Posts
    100

    whts wrong with the sql statement [resolved]

    i have a code from some source that display data from database to the flexgrid.

    the prob is i want the data to be displayed depend on the selected date.
    so i just put the sql statement which i think (may be the sql statement is wrong..) will display data according to the date.
    and, an error ocurred whis is datatype mismatch and it points to the sql statement. why is that so??

    VB Code:
    1. Private Sub Command4_Click()
    2. On Error GoTo errHandler
    3. Set Conn = GetConnection
    4. Set rs = New ADODB.Recordset
    5. rs.Open "SELECT * FROM pemeriksaanBM WHERE tarikh = '" & DTPicker1.Value & "'", Conn, adOpenStatic, adLockOptimistic
    6. 'rs.Open "SELECT * FROM pemeriksaanBM ", Conn, adOpenStatic, adLockOptimistic
    7.  
    8. With rs
    9.     If Not .EOF Then
    10.       FG_ShowRecordset MSFlexGrid2, rs
    11.     End If
    12.     .Close
    13.   End With
    14.   Conn.Close
    15.  
    16. Set Conn = Nothing
    17.   Set rs = Nothing
    18.   Exit Sub
    19.  
    20. errHandler:
    21.   MsgBox "An error occured." & vbLf & Err.Number & ": " & Err.Description, vbCritical
    22.   Set Conn = Nothing
    23.   Set rs = Nothing
    24.  
    25. End Sub
    Last edited by azrina; Jan 25th, 2004 at 05:01 PM.

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Not sure if it's this line you mean, but see if this changes anything

    rs.Open "SELECT * FROM pemeriksaanBM WHERE tarikh = " & DTPicker1.Value, Conn, adOpenStatic, adLockOptimistic

    Or if you need the quotes around your DTPicker1.Value

    rs.Open "SELECT * FROM pemeriksaanBM WHERE tarikh = " & """" & DTPicker1.Value & """", Conn, adOpenStatic, adLockOptimistic

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2004
    Posts
    100
    are u sure with what u are saying ??
    that makes syntax error..
    do u have any good solution ?(besides that)

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    azrina


    Do this before posting sql statement, usually you can see whats wrong with the syntax:

    VB Code:
    1. SQL = "SELECT * FROM pemeriksaanBM WHERE tarikh = '" & DTPicker1.Value & "'"
    2. Debug.Print SQL

    What database are you using? This makes a difference in the date syntax.

    ex.

    Access - enclose date - # Date #
    Last edited by randem; Jan 25th, 2004 at 04:52 PM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2004
    Posts
    100
    i use access 2003

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    azrina


    Use


    "SELECT * FROM pemeriksaanBM WHERE tarikh = #" & DTPicker1.Value & "#"

    of course tarikh should be an actual date field type.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2004
    Posts
    100
    thank u randem...it works

    hope, u can help me again next time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width