|
-
Jan 25th, 2004, 03:21 PM
#1
Thread Starter
Lively Member
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:
Private Sub Command4_Click()
On Error GoTo errHandler
Set Conn = GetConnection
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM pemeriksaanBM WHERE tarikh = '" & DTPicker1.Value & "'", Conn, adOpenStatic, adLockOptimistic
'rs.Open "SELECT * FROM pemeriksaanBM ", Conn, adOpenStatic, adLockOptimistic
With rs
If Not .EOF Then
FG_ShowRecordset MSFlexGrid2, rs
End If
.Close
End With
Conn.Close
Set Conn = Nothing
Set rs = Nothing
Exit Sub
errHandler:
MsgBox "An error occured." & vbLf & Err.Number & ": " & Err.Description, vbCritical
Set Conn = Nothing
Set rs = Nothing
End Sub
Last edited by azrina; Jan 25th, 2004 at 05:01 PM.
-
Jan 25th, 2004, 03:30 PM
#2
Frenzied Member
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
-
Jan 25th, 2004, 03:42 PM
#3
Thread Starter
Lively Member
are u sure with what u are saying ??
that makes syntax error..
do u have any good solution ?(besides that)
-
Jan 25th, 2004, 04:38 PM
#4
azrina
Do this before posting sql statement, usually you can see whats wrong with the syntax:
VB Code:
SQL = "SELECT * FROM pemeriksaanBM WHERE tarikh = '" & DTPicker1.Value & "'"
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.
-
Jan 25th, 2004, 04:43 PM
#5
Thread Starter
Lively Member
-
Jan 25th, 2004, 04:54 PM
#6
azrina
Use
"SELECT * FROM pemeriksaanBM WHERE tarikh = #" & DTPicker1.Value & "#"
of course tarikh should be an actual date field type.
-
Jan 25th, 2004, 04:59 PM
#7
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|