SQL Limit clause - vb.net

1.5k Views Asked by At

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.

2

There are 2 best solutions below

2
Vivek S. On BEST ANSWER

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 ''

0
Vipin Jain On

= 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 & ";