Click here to Skip to main content
15,921,371 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# code Pin
Abhinav S10-Apr-12 19:39
Abhinav S10-Apr-12 19:39 
QuestionHow to make a new MDI child form maximum size? Pin
fantasy121510-Apr-12 15:42
fantasy121510-Apr-12 15:42 
AnswerRe: How to make a new MDI child form maximum size? Pin
Karthik Harve10-Apr-12 18:17
professionalKarthik Harve10-Apr-12 18:17 
GeneralRe: How to make a new MDI child form maximum size? Pin
fantasy121510-Apr-12 22:56
fantasy121510-Apr-12 22:56 
QuestionList Box Sudden Exit On Selection Pin
PDTUM10-Apr-12 13:33
PDTUM10-Apr-12 13:33 
AnswerRe: List Box Sudden Exit On Selection Pin
Richard Andrew x6410-Apr-12 14:01
professionalRichard Andrew x6410-Apr-12 14:01 
AnswerRe: List Box Sudden Exit On Selection Pin
Luc Pattyn10-Apr-12 15:35
sitebuilderLuc Pattyn10-Apr-12 15:35 
AnswerRe: List Box Sudden Exit On Selection Pin
PDTUM11-Apr-12 5:52
PDTUM11-Apr-12 5:52 
AnswerRe: List Box Sudden Exit On Selection Pin
BobJanova10-Apr-12 23:21
BobJanova10-Apr-12 23:21 
QuestionC# App to/from MetaTrader 4 Pin
iltallman10-Apr-12 12:28
iltallman10-Apr-12 12:28 
QuestionHow I can isolate a Keyboard in the operative system? Pin
tsw198510-Apr-12 7:49
tsw198510-Apr-12 7:49 
AnswerRe: How I can isolate a Keyboard in the operative system? Pin
Dave Kreskowiak10-Apr-12 8:11
mveDave Kreskowiak10-Apr-12 8:11 
GeneralRe: How I can isolate a Keyboard in the operative system? Pin
tsw198510-Apr-12 10:05
tsw198510-Apr-12 10:05 
GeneralRe: How I can isolate a Keyboard in the operative system? Pin
Dave Kreskowiak10-Apr-12 10:24
mveDave Kreskowiak10-Apr-12 10:24 
GeneralRe: How I can isolate a Keyboard in the operative system? Pin
tsw198510-Apr-12 10:45
tsw198510-Apr-12 10:45 
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 

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.