Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
GeneralRe: How I can isolate a Keyboard in the operative system? Pin
PIEBALDconsult10-Apr-12 11:37
mvePIEBALDconsult10-Apr-12 11:37 
GeneralRe: How I can isolate a Keyboard in the operative system? Pin
Dave Kreskowiak10-Apr-12 14:21
mveDave Kreskowiak10-Apr-12 14:21 
GeneralRe: How I can isolate a Keyboard in the operative system? Pin
tsw198511-Apr-12 1:17
tsw198511-Apr-12 1:17 
AnswerRe: How I can isolate a Keyboard in the operative system? Pin
jschell10-Apr-12 8:32
jschell10-Apr-12 8:32 
AnswerRe: How I can isolate a Keyboard in the operative system? Pin
PIEBALDconsult10-Apr-12 10:40
mvePIEBALDconsult10-Apr-12 10:40 
QuestionSend SMS using GSM modem Pin
zakirox12310-Apr-12 5:50
zakirox12310-Apr-12 5:50 
AnswerRe: Send SMS using GSM modem Pin
kevinnicol10-Apr-12 6:33
kevinnicol10-Apr-12 6:33 
Questionc# calling Stored Procedures Pin
si_6910-Apr-12 5:39
si_6910-Apr-12 5:39 
Hi All

I am trying to create a generic method for calling stored procedures

I would like to pass in the Parameters in via an array

At the moment i am having trouble adding the parameters to the SqlCommand

This is what i have so far

Can anyone advise

thanks

Simon

Calling the method
string[] paramNames = new string[1];
paramNames[0] = "@date = 2012-1-1";
string err="";

WriteToDatabase("exec LoadData", CommandType.StoredProcedure, paramNames, out err); 


Method
public static bool WriteToDatabase( 
        string sql, 
        CommandType commandType, 
        string[] paramNames, 
        out string errorText) 
    { 
        bool success = false; 
        errorText = ""; 
        try 
        { 
            using (SqlConnection connection = new SqlConnection(ConnectionString)) 
            { 
               connection.Open();  
                List<SqlParameter> parameters = new List<SqlParameter>(); 
 
                foreach (string paramName in paramNames) 
                { 
                    parameters.Add(new SqlParameter() { ParameterName = paramName }); 
                } 
 
                using (SqlCommand command = new SqlCommand() 
                { 
                    Connection = connection, 
                    CommandText = sql, 
                    CommandType = commandType, 
                    Parameters = parameters 
 
                }) 
                 command.ExecuteNonQuery();   
 
                 connection.Close(); 
            } 
 
 
        } 

AnswerRe: c# calling Stored Procedures Pin
Pete O'Hanlon10-Apr-12 5:47
mvePete O'Hanlon10-Apr-12 5:47 
AnswerRe: c# calling Stored Procedures Pin
jschell10-Apr-12 8:36
jschell10-Apr-12 8:36 
AnswerRe: c# calling Stored Procedures Pin
PIEBALDconsult10-Apr-12 10:04
mvePIEBALDconsult10-Apr-12 10:04 
Questiontext file application Pin
torres110-Apr-12 5:12
torres110-Apr-12 5:12 
AnswerRe: text file application Pin
Not Active10-Apr-12 5:16
mentorNot Active10-Apr-12 5:16 
AnswerRe: text file application Pin
VJ Reddy10-Apr-12 7:39
VJ Reddy10-Apr-12 7:39 
GeneralRe: text file application Pin
Vipin_Arora11-Apr-12 20:29
Vipin_Arora11-Apr-12 20:29 
GeneralRe: text file application Pin
VJ Reddy11-Apr-12 20:47
VJ Reddy11-Apr-12 20:47 
AnswerRe: text file application Pin
Vipin_Arora11-Apr-12 20:26
Vipin_Arora11-Apr-12 20:26 
QuestionRegarding heat maps Pin
smsravanth10-Apr-12 2:05
smsravanth10-Apr-12 2:05 
AnswerRe: Regarding heat maps Pin
ddecoy10-Apr-12 2:39
ddecoy10-Apr-12 2:39 
AnswerRe: Regarding heat maps Pin
V.10-Apr-12 3:17
professionalV.10-Apr-12 3:17 
GeneralRe: Regarding heat maps Pin
harold aptroot10-Apr-12 3:25
harold aptroot10-Apr-12 3:25 
QuestionSuggestion needs Pin
anishkannan10-Apr-12 1:18
anishkannan10-Apr-12 1:18 
AnswerRe: Suggestion needs Pin
PIEBALDconsult10-Apr-12 2:48
mvePIEBALDconsult10-Apr-12 2:48 
AnswerRe: Suggestion needs Pin
V.10-Apr-12 3:12
professionalV.10-Apr-12 3:12 
AnswerRe: Suggestion needs Pin
VJ Reddy10-Apr-12 6:56
VJ Reddy10-Apr-12 6:56 

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.