Thursday, September 14, 2017

generic, hacky, let's-update-the-database thing in C#

using System.Data.SqlClient;
using WelderConsoleApp.Interfaces;
namespace WelderConsoleApp.ExternalDependencies
{
   public class DatabaseManipulations : IDatabaseManipulations
   {
      public void UpdateGetWelderData(string connectionString)
      {
         using (SqlConnection sqlConnection = new SqlConnection(connectionString))
         {
            using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
            {
               sqlCommand.CommandText = "UPDATE Employee SET WelderStencil =
                     @value WHERE HRRef = @key";
               sqlCommand.Parameters.AddWithValue("@key", "215527");
               sqlCommand.Parameters.AddWithValue("@value", "yay");
               sqlConnection.Open();
               sqlCommand.ExecuteNonQuery();
               sqlConnection.Close();
            }
         }
      }
   }
}

No comments:

Post a Comment