Thursday, January 17, 2013

define a parameter for a sproc in C# (yawn)

private void UseAddStoredProcedure(string newEntry)
{
   try
   {
      using (SqlConnection sqlConnection = new SqlConnection(AddConnectionString()))
      {
         using (SqlCommand sqlCommand = new SqlCommand())
         {
            sqlCommand.CommandText = addStoredProcedure;
            sqlCommand.Parameters.Add("@Item", SqlDbType.VarChar).Value = newEntry;
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Connection = sqlConnection;
            sqlConnection.Open();
            sqlCommand.ExecuteNonQuery();
         }
      }
   }
   catch
   {
      throw new System.ApplicationException(addStoredProcedure + " failed");
   }
}

No comments:

Post a Comment