Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai friends,

This is the code for storedprocedure for insert update delete.
Alter PROCEDURE MasterInsertUpdateDelete

(

    @id         INTEGER,

    @first_name  VARCHAR(10),

    @last_name   VARCHAR(10),

    @salary      DECIMAL(10,2),

    @city        VARCHAR(20), 

    @StatementType nvarchar(20) = ''

)

 

AS

BEGIN

IF @StatementType = 'Insert'

BEGIN

insert into employee (id,first_name,last_name,salary,city) values( @id, @first_name,  @last_name,  @salary, @city)   

END

 

IF @StatementType = 'Select'

BEGIN

select * from employee

END 

 

IF @StatementType = 'Update'

BEGIN

UPDATE employee SET

            First_name =  @first_name, last_name = @last_name, salary = @salary,

            city = @city

      WHERE id = @id

END

 

else IF @StatementType = 'Delete'

BEGIN

DELETE FROM employee WHERE id = @id

END

end


How can we call this in c sharp by coding for insert method.
Posted
Comments
[no name] 28-Jul-12 14:43pm    
I am confused. You know how to call stored procedures so why are you asking how to call stored procedures?
baskaran chellasamy 28-Jul-12 15:03pm    
How can we call this stored procedure in c sharp by coding for delete query.because @id parameter is enough for deleting the row.but when calling this through this stored procedure we must enter all parameter to deleting process.if we enter the @id and statementType two parameters for delete,is this executed?
Trak4Net 28-Jul-12 16:04pm    
Your procedure parameters do not have default values except for statementType so the must be populated even if you set null values. If you have control over this procedure and you don't want to have to code those extra parameters then change your stored procedure to have default values.

1 solution

This is retarded. You asked if this was a good idea, and I said no. I've never seen anyone do this, it's ridiculous. Passing in a STRING for statement type, is pure idiocy. So if someone mistypes the word 'insert' in their proc call, it will run fine, and do NOTHING ?

Get rid of this code and forget you ever thought this was a good idea. Replace it with sane procs for each action. Then call it the way you'd call any proc, as widely documented on the web.
 
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