Click here to Skip to main content
Sign Up to vote bad
good
See more: C#4.0
hi this is Hem Raj Thakur
How to implement this store procedure in a c# code?
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 11 Feb '13 - 18:09
Edited 14 Feb '13 - 9:20
ryanb3143.9K

Comments
Guirec Le Bars - 12 Feb '13 - 0:41
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:55
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:10
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.
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.
}
  Permalink  
Comments
Espen Harlinn - 14 Feb '13 - 15:55
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,386
1 OriginalGriff 6,596
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid