Click here to Skip to main content
15,890,557 members
Home / Discussions / C#
   

C#

 
QuestionSMS from C# windows application Pin
karthisomu17-Feb-13 21:21
karthisomu17-Feb-13 21:21 
AnswerRe: SMS from C# windows application Pin
Richard MacCutchan17-Feb-13 21:58
mveRichard MacCutchan17-Feb-13 21:58 
AnswerRe: SMS from C# windows application Pin
Blikkies17-Feb-13 22:37
professionalBlikkies17-Feb-13 22:37 
AnswerRe: SMS from C# windows application Pin
Azza ALbelushi18-Feb-13 4:08
Azza ALbelushi18-Feb-13 4:08 
AnswerRe: SMS from C# windows application Pin
Amir Mohammad Nasrollahi29-Jul-13 22:06
professionalAmir Mohammad Nasrollahi29-Jul-13 22:06 
QuestionDetecting Drawn Objects Pin
ASPnoob17-Feb-13 20:54
ASPnoob17-Feb-13 20:54 
AnswerRe: Detecting Drawn Objects Pin
Richard MacCutchan17-Feb-13 21:56
mveRichard MacCutchan17-Feb-13 21:56 
QuestionHow to use Param with Enum Pin
demoninside917-Feb-13 19:25
demoninside917-Feb-13 19:25 
hi all,

actually I recently made a web application. I have around 20 store procedures [for insert, update and delete] , around 12 store procedures are having different numbers of procedures.

I made different functions for every single operation, like see the code below
C#
#region Update Comment
    public int Update_Comment(string Comment, string Leave_ID)
    {
        SqlCommand com = new SqlCommand("Update_Comments", con);
        com.CommandType =CommandType.StoredProcedure;
        com.Parameters.Add("@Comments",SqlDbType.NVarChar,1000).Value =Comment;
        com.Parameters.Add("@Leave_ID", SqlDbType.NVarChar, 50).Value = Leave_ID;
        con.Open();
        int row = com.ExecuteNonQuery();
        con.Dispose();
        con.Close();
        return row;

    }
    #endregion


 #region Updating Leave after approval
    public int Updating_Leave(string User_Id, string Leave_Type, int Leave_Applied)
    {
        SqlCommand com = new SqlCommand("Update_Leave", con);
        com.CommandType =CommandType.StoredProcedure;
        com.Parameters.Add("@User_Id",SqlDbType.NVarChar,50).Value = User_Id;
        com.Parameters.Add("@Leave_Type", SqlDbType.NVarChar, 50).Value = Leave_Type;
        com.Parameters.Add("@Leave_Applied", SqlDbType.Int).Value = Leave_Applied;
        con.Open();
        int row = com.ExecuteNonQuery();
        con.Dispose();
        con.Close();
        return row;
        
    }
    #endregion


CSS
here are two function first function is having 2 parametrs and the second one is having 3, but rest of the code is SAME.

So can it be possible, with the help of enum and param we can reduce the no of functions I made. all 12 functions are having different numbers of parameters.

can we reduce 20 functions to 1 or 2 functions [functions may be lengthy; having many if/else conditions] ? is this possible.



for that I did like below
C#
 enum Operation_Type
    {
        Insert,
        Update,
        Delete,
        Select
    }


public void Do_Insert_Update_Delete(string Proc_Name, Operation_Type Type ,int No_Of_Args , params object[] args)
    {
        if(Operation_Type.Insert ==Type)
        {
            SqlCommand com =new SqlCommand(Proc_Name,con);
            com.CommandType = CommandType.StoredProcedure;
            for(int i=1; i== No_Of_Args; i++)
            {
            com.Parameters.AddWithValue(args);
            }
            con.Open();
            com.ExecuteNonQuery();
            con.Close();
            con.Dispose();

        }
        
    }

But I am not getting how to pass parameters and Proc_Name in the code above.
Please let me know
Thanks
Gaurav
Question4 Images change on linkbutton click Pin
sahavasiwebwonders17-Feb-13 18:25
sahavasiwebwonders17-Feb-13 18:25 
AnswerRe: 4 Images change on linkbutton click Pin
Pete O'Hanlon17-Feb-13 20:48
mvePete O'Hanlon17-Feb-13 20:48 
GeneralRe: 4 Images change on linkbutton click Pin
sahavasiwebwonders17-Feb-13 21:03
sahavasiwebwonders17-Feb-13 21:03 
GeneralRe: 4 Images change on linkbutton click Pin
Pete O'Hanlon17-Feb-13 22:36
mvePete O'Hanlon17-Feb-13 22:36 
QuestionImages change on linkbutton click Pin
sahavasiwebwonders17-Feb-13 18:24
sahavasiwebwonders17-Feb-13 18:24 
AnswerRe: Images change on linkbutton click Pin
Richard MacCutchan17-Feb-13 21:52
mveRichard MacCutchan17-Feb-13 21:52 
QuestionWebMatrix-Following Pin
Bram van Kampen16-Feb-13 15:12
Bram van Kampen16-Feb-13 15:12 
AnswerRe: WebMatrix-Following Pin
David C# Hobbyist.16-Feb-13 16:19
professionalDavid C# Hobbyist.16-Feb-13 16:19 
GeneralRe: WebMatrix-Following Pin
Bram van Kampen16-Feb-13 17:19
Bram van Kampen16-Feb-13 17:19 
AnswerRe: WebMatrix-Following Pin
N a v a n e e t h16-Feb-13 18:00
N a v a n e e t h16-Feb-13 18:00 
GeneralRe: WebMatrix-Following Pin
Bram van Kampen17-Feb-13 14:45
Bram van Kampen17-Feb-13 14:45 
GeneralRe: WebMatrix-Following Pin
N a v a n e e t h17-Feb-13 17:10
N a v a n e e t h17-Feb-13 17:10 
AnswerRe: WebMatrix-Following Pin
Dave Kreskowiak16-Feb-13 18:50
mveDave Kreskowiak16-Feb-13 18:50 
GeneralRe: WebMatrix-Following Pin
Bram van Kampen17-Feb-13 14:50
Bram van Kampen17-Feb-13 14:50 
QuestionWebMatrix Pin
Bram van Kampen16-Feb-13 14:26
Bram van Kampen16-Feb-13 14:26 
AnswerRe: WebMatrix Pin
N a v a n e e t h16-Feb-13 18:01
N a v a n e e t h16-Feb-13 18:01 
QuestionParsing a web page to get just the <p> inner text. Pin
David C# Hobbyist.16-Feb-13 6:49
professionalDavid C# Hobbyist.16-Feb-13 6:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.