Using SQL Server 2005 and VB.Net
Table1
ID Name Dept
001 Raja IT
002 Ravi CSE
003 Suns IT
Stored Procedure
Create Procedure Selecttable1 As Select ID, Name, Dept from table1
I want to execute the stored procedure with condition like
cmd = new sqlcommand("Exec SelectTable1 where id like '" & idsearch.Text & "%' ", dbcon)
cmd.ExecuteNonQuery
idsearch.Text – Textbox Input value
When I try to run the above query it was showing error.
How to execute a stored procedure with conditions?
Need Query Help
You seem to be looking for running a stored procedure with parameters.
For this both the stored procedure needs to be created with parameters, and the code calling it should pass those in.
Stored Procedure:
Code:
Do not use a construct like in your example (
"Exec SelectTable1 where id like '" & idsearch.Text & "%' "), as this is an open SQL Injection vulnerability.You should use parameters, as described above in order to avoid this.