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
<pre lang=
"
vb"
>y codes:
this code is executed when the command cmdLoad button is clicked
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
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="
& Application.StartupPath &
"
\Library2.mdb; JET OleDb:Database Password=3Musketeers"
adap1 =
New
OleDbDataAdapter(newSQL, con)
con.Open()
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
con.Close()
End
Sub
Hope someone could help me...
thanks in advance
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
[
^
]
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.