-1

I've been trying to find a solution to my query regarding the LIMIT Clause, here's my code,

    "SELECT * FROM tbl_student WHERE s_grade='" & grade.Text & "' AND s_status='Validated' ORDER BY s_id_no ASC LIMIT 10"

I was wondering if could do,

    "SELECT * FROM tbl_student WHERE s_grade='" & grade.Text & "' AND s_status='Validated' ORDER BY s_id_no ASC LIMIT='" & txt_limit.Text & "'"

Getting the limit value based on my selection which contains the limit, but failed to do so, i get this syntax error.

Vivek S.
  • 19,945
  • 7
  • 68
  • 85
Leo Elvin Lee
  • 189
  • 1
  • 6
  • 16

2 Answers2

1

= sign not use with LIMIT
try this

 "SELECT * FROM tbl_student WHERE s_grade='" & grade.Text & "' AND
 s_status='Validated' ORDER BY s_id_no ASC LIMIT " & txt_limit.Text & ";
Vipin Jain
  • 3,686
  • 16
  • 35
1

Change LIMIT='" & txt_limit.Text & "' to LIMIT " & txt_limit.Text & "

Two corrections
1.) LIMIT=: = is invalid for LIMIT clause
2.) '" & txt_limit.Text & "': You're concatenating it as string because
you've used '' the command text produce LIMIT '10', so you should avoid it ''

Vivek S.
  • 19,945
  • 7
  • 68
  • 85
  • well that did the trick and also thanks for the explanation, now I know. – Leo Elvin Lee Jan 28 '16 at 05:44
  • @LeoElvinLee **I strongly recommend to use [parameterized SQL query](http://stackoverflow.com/questions/542510/how-do-i-create-a-parameterized-sql-query-why-should-i)** – Vivek S. Jan 28 '16 at 05:46