Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have created dynamic sp statement in c# as
 StringBuilder SQLquery = new StringBuilder();
for loop here

SQLquery.Append(" exec  usp_pv_ChangeStatus  4)   
SQLquery.Append(" # ");
SQLquery.Append(" exec  usp_pv_ChangeStatus  4)   
SQLquery.Append(" # ");

  int retinsertTemp = objPvbll.executeSqlquery(SQLquery.ToString(), out suceesFlag);


I have already created a stored procedure "usp_pv_ChangeStatus" in sql server

I have a executesql procedure in sql server which will execute this sp

SQL
ALTER proc [dbo].[usp_pv_ExecuteSqlquery]
@sqlqueries varchar(max),@suceesFlag int out
as
BEGIN

SET @sqlqueries = REPLACE ( @sqlqueries , '#' , CHAR(13) + CHAR(10) )

PRINT @sqlqueries
exec(@sqlqueries)
end


but its not working ,please help
Posted
Comments
Maciej Los 11-Apr-14 2:57am    
"Not working" is not informative at all. Please, be more specific and provide more details.

1 solution

Please, read my comment to the question first.

The way you're trying to achieve that is wrong!

Instead creating "dynamic query" to call sp in it, call stored procedure directly!
Have a look here: How to: Create and Execute an SQL Statement that Returns a Single Value[^]
When you open above link, on the left side of window, you'll find many usefull links about executing queries.

I must warn you about SQL Injection: How To: Protect From SQL Injection in ASP.NET[^]

If you would like to display data using sp, please see: Walkthrough: Displaying Data Using a Stored Procedure in the GridView Web Server Control[^]
 
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