Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 19:09pm
Edited 14-Feb-13 10:20am
RyanDev124.9K
v2
Comments
Guirec Le Bars at 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 at 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 at 12-Feb-13 1:10am
   
Are you using Entity Framework or any other ORM in your c# application?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 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)

  Print Answers RSS
0 OriginalGriff 295
1 Maciej Los 280
2 Afzaal Ahmad Zeeshan 224
3 BillWoodruff 205
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100