Good advice about getting to DRY

I stumbled across this today and it rings very true.

Importance of reuse
Code reuse has been a topic that seems to keep coming up in my work over and over again. Its probably because I keep seeing repeated code that doesn’t need to be repeated. Its important to realize that the best way to make code reusable is by repeating yourself first and then refactoring. Had I tried to do it the other way around I would have probably solved the wrong problem.

Author: Korey Hinton

How to read an Excel file into a Dataset

If you need to read an Excel file into a dataset so you can work with the data, try this:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyNamespace
    public class ExcelReader
        public DataSet ConvertExcelFileToDataSet(string folderPath, string fileName)
            //string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + folderPath + ";Extended Properties=\"text;Excel 8.0;HDR=No;FMT=Delimited\"";
            string connString = "provider=Microsoft.ACE.OLEDB.12.0;" + "data source=" + folderPath + "\\" + fileName + ";Extended Properties=\"Excel 12.0;HDR=Yes\"";
            //string connString = Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myOldExcelFile.xls;
            //Extended Properties = "Excel 8.0;HDR=YES";
            DataSet ds = new DataSet();

            using (OleDbConnection oledbConn = new OleDbConnection(connString))
                //_logger.WriteToLog(className + " " + "IMPORT:Opening file-" + folderPath + "\\" + fileName);
                OleDbDataAdapter oleda = new OleDbDataAdapter();
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
                oleda.SelectCommand = cmd;
                oleda.Fill(ds, "Table1");
                //_logger.WriteToLog(className + " " + "IMPORT:Dataset fill for file-" + folderPath + "\\" + fileName + " was successful");
            return ds;


Calling a Stored Procedure from using my repository behavior

When using my repository code, this is the way to call a stored procedure from within a C# project:

      public void DeleteRelatedTemplatedTimeEntries(int id)

            string commandText = "exec usp_DeleteTemplatedTimeEntryByTemplateId @TemplateId";
            var p = new SqlParameter();
            p.DbType = DbType.Int16;
            p.Value = id;
            p.ParameterName = "@TemplateId";
            SqlParameter[] ps = new SqlParameter[]{p};
            _repoBehavior.ExecuteStoreCommand(commandText, ps);
            //_repoBehavior.ExecuteStoredProcedure(commandText, ps);

Enabling cross site access for WebAPI

If you can’t access your webAPI functions from another site, this is normal in To fix it, Open ‘Manage Nuget Packages’ and add the ‘Microsoft.ASPNet.WebApi.Cors’ (Cross Origin support) package.

Then in your controller, add this to your using statements:

using System.Web.Http.Cors;

and add this attribute to your controller class:


Note this will allow access from anywhere.