Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written single stored procedure for insert,update,delete and select.my procedure is:

ALTER PROCEDURE [dbo].[artdetails1]
(
	@artdetailId int,
	@artDescription varchar(50),
	@artShortdesc varchar(50),
	@artValidity varchar(50),
	@artStatus varchar(50),
	@StatementType varchar(50)
	
)
	
AS
BEGIN
	
	
	BEGIN
	IF @StatementType = 'Insert'
		BEGIN
	           insert into artdetails(artDescription,artShortdesc,artValidity,artStatus)
	            values(@artDescription,@artShortdesc,@artValidity,@artStatus)   
			
               END
 
	IF @StatementType = 'Select'
		BEGIN
				select * from artdetails
		END 
 
	IF @StatementType = 'Update'
		BEGIN
			update artdetails SET
			artDescription=@artDescription,artShortdesc=@artShortdesc,
			artValidity=@artValidity,artStatus=@artStatus
            	        where artdetailId= @artdetailId
	        END
 
	else IF @StatementType = 'Delete'
			BEGIN
				Update artist SET @artStatus= 'not available';
			END
	end
end

But i am confused how can i check the statement type in C# code and call this procedure.Please help.I am new to sql.
Posted

1 solution

Try like this:
C#
cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandText = "artdetails1";
cmd.Parameters.Add(new SqlParameter("@parametername", SqlDbType.VarChar, 50));
cmd.Parameters["@StatementType "].Value = "Insert";//query type
 
Share this answer
 
Comments
Bh@gyesh 23-Apr-14 0:39am    
Want to add something in Jas' solution.

cmd.Connection = cn;
cn.open();

At last you can add :
cn.Close();
Tom Marvolo Riddle 23-Apr-14 0:49am    
Thanks for the info Bhagyesh; .OP wants to call particular query in a Stored procedure(It is clear that he/she knows how to call a SP)
I hope OP knows how to handle connection.That's why i left it.

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