Click here to Skip to main content
15,886,806 members
Home / Discussions / C#
   

C#

 
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 
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 
0) It probably shouldn't be static.
1) You should probably not keep creating the Connection and Command -- create one and hold onto it (in the closed state).
2) Where does ConnectionString come from?
3) Here's your code with a few changes. It compiles, but it's untested:

public static bool WriteToDatabase(
    string sql,
    System.Data.CommandType commandType,
    out string errorText,
    params System.Tuple<string,object>[] values
)
{
    bool success = true;
    errorText = null;

    using (System.Data.IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionString))
    {
      try
      {
        using (System.Data.IDbCommand command = connection.CreateCommand() )
        {
          command.CommandText = sql ;
          command.CommandType = commandType ;

          foreach (System.Tuple<string,object> param in values )
          {
            System.Data.IDbDataParameter p = command.CreateParameter() ;
            p.ParameterName = param.Item1 ;
            p.Value = param.Item2 ;
            command.Parameters.Add(p);
          }

         connection.Open();
         command.ExecuteNonQuery();
        }
      }
      catch ( System.Exception err )
      {
        success = false ;
        errorText = err.ToString() ;
      }
      finally
      {
         connection.Close();
      }
    }

    return ( success ) ;
}

    WriteToDatabase
    (
      "blah blah blah"
    ,
      System.Data.CommandType.Text
    ,
      out error
    ,
      new System.Tuple<string,object> ( "@date" , System.DateTime.Now )
    ) ;

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 
GeneralIntegrate Window Application With Google Map Pin
SYEDGOHAR10-Apr-12 0:35
SYEDGOHAR10-Apr-12 0:35 
GeneralRe: Integrate Window Application With Google Map Pin
ddecoy10-Apr-12 2:42
ddecoy10-Apr-12 2:42 
GeneralIntegrate Window Application With Google Map Pin
SYEDGOHAR10-Apr-12 0:26
SYEDGOHAR10-Apr-12 0:26 

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.