Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Hi Guys,
I am doing an Electronic Library Management System that includes counting of time for each student who logged in every time he/she goes or used e-library. But I'm having trouble in frmReserve.

Here is the error that I got:
Syntax error in date in query expression 'tblReserve.studID=tblStudents.StudNumber and tblReserve.inDate =#00/30/2012#'.

Below are m
PERL
<pre lang="vb">
y codes:
this code is executed when the command cmdLoad button is clicked

VB
Private Sub cmdLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoad.Click
       MsgBox(Today.ToString)
       paintStudList("SELECT tblReserve.pcNum, tblStudents.FullName, tblReserve.numOfTime FROM tblReserve,tblStudents where tblReserve.studID=tblStudents.StudNumber and tblReserve.inDate =#" & Today.ToString("mm/dd/yyyy") & "#", dgrid2, "PC NUMBER", "STUDENT NAME", "NUMBER OF TIME")
       dgrid2.Columns.Item(0).ReadOnly = True
       dgrid2.Columns.Item(1).ReadOnly = True
   End Sub


the following codes are executed if the SQL above is true

VB
Sub paintStudList(ByVal newSQL As String, ByVal myGrid As System.Object, ByVal str1 As String, ByVal str2 As String, ByVal str3 As String)
        Dim adap1 As OleDbDataAdapter
        Dim dt1 As New DataTable
        Dim con As New OleDbConnection

        'con.ConnectionString = "PROVIDER=Microsoft.Jet.OleDb.4.0; Data Source=Library2.mdb; JET OleDb:Database Password=3Musketeers"
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\Library2.mdb; JET OleDb:Database Password=3Musketeers"
        'Data Source=" & Application.StartupPath & "\location.mdb"

        adap1 = New OleDbDataAdapter(newSQL, con)
        con.Open()
        'fill data to datable
        adap1.Fill(dt1)
        myGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing

        dt1.Columns.Item(0).ColumnName = str1
        dt1.Columns.Item(1).ColumnName = str2
        dt1.Columns.Item(2).ColumnName = str3
        myGrid.DataSource = dt1
        'bsource.DataSource = dt1
        con.Close()
    End Sub




Hope someone could help me...
thanks in advance
Posted

Replace the "#" characters with quotes, and put the date into ISO format:

VB
paintStudList("SELECT tblReserve.pcNum, tblStudents.FullName, tblReserve.numOfTime FROM tblReserve,tblStudents where tblReserve.studID=tblStudents.StudNumber and tblReserve.inDate ='" & Today.ToString("yyyy-MM-dd") & "'", dgrid2, "PC NUMBER", "STUDENT NAME", "NUMBER OF TIME")
 
Share this answer
 
If you used a parameterized query instead of this very shaky string concatentation, you wouldn't have this problem at all and your code would be much more readable and maintainable.

VB.NET Parameterized Query[^]
 
Share this answer
 
Hi OriginalGriff,

I already resolved this by myself. The thing here is that, I did not noticed that the tblReserve.studID field on my database is in different data type (Text) whereas tblStudents.StudNumber is in Integer format. But still thanks for your quick response. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900