Click here to Skip to main content
15,886,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi this is Hem Raj Thakur
How to implement this store procedure in a c# code?
SQL
Create 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

Thanks in advance.
Posted
Updated 14-Feb-13 9:20am
v2
Comments
Guirec 12-Feb-13 0:41am    
Please complete your question:
do you want to completely get rid of the stored procedure and then do a rewrite in C# ? or do you want to make a call to your procedure from C#?
Hem Raj Thakur 12-Feb-13 0:55am    
I wanna Implement this store procedure in a c# application. how can i pass parameters in save Update help of this sp.
Kiran Susarla 12-Feb-13 1:10am    
Are you using Entity Framework or any other ORM in your c# application?

1 solution

Here is a skeleton of one way to do this. Fill in the blanks and see where it gets you.
C#
private enum StatementType
{
   Insert,
   Update,
   Delete
}
private void MasterInsertUpdateDelete( int id, string first, string last, double salary, string city, StatementType statementType )
{
   switch( statementType )
   {
      case StatementType.Insert:
         // Build a query based on this statement type
         // For the love of god use paramatarized queries
         break;

      case StatementType.Update:
         // Build a query based on this statement type
         // For the love of god use paramatarized queries
         break;

      case StatementType.Delete:
         // Build a query based on this statement type
         // For the love of god use paramatarized queries
         break;
   }

   // Build a connection object <a href="http://support.microsoft.com/kb/308611">How to do this</a>   
   // Execute it.
}
 
Share this answer
 
Comments
Espen Harlinn 14-Feb-13 15:55pm    
Going from what he has to this shouln't be difficult at all :-D

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