Monday, March 12, 2018

Entity Framework: Model successfully updated but changes are not available in code

I lost quite some time on this annoying issue that sometimes affects my VisualStudio 2015 with the Devart Oracle Driver for using Entity Framework.

My changes in the database (for example a modification of a view) were reflected ONLY in the entity framework model (after selecting the usual Update Model from Database...) but the modified classes WERE NOT available in the code!

The solution is very simple: "Run Custom Tool"

Select your model file (the one with extension with .edml), right click an choose "Run Custom Tool".

Now the changes to your database are available in your code too.


Sunday, February 18, 2018

Where is java on macOS?

Open the terminal and execute the following command:

/usr/libexec/java_home -v 1.7

It will locate the files corresponding to the provided java version.
Here the link for Java6 from Apple (useful is you want to install Matlab):

Thursday, January 25, 2018

Excel-Files take way too to open [Windows 10 issue on Dell]

This is not strictly speaking a programming issue, but definitely something quite annoying.
On my Windows 10 on my DELL  OptiPlex,  opening an excel file used to take about 30 seconds! It didn't matter if the file was on a local or network folder!
The issue was, in my case, related to the Audio Driver. Yes! An issue with Excel was related to the Realtek's Audio Driver!

Anyway, here is the Dell's post:


Find your Computer Version in and update your Audio Driver

Monday, December 11, 2017

C#: Import excel file as dataset using OLEDB

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace cltStammdatenImporterGUI
    public class ExcelFile

        public static DataSet DataSetFromExcelFile(string sExcelFilename, string sExcelRange = "")
            DataSet ds = new DataSet();

            string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sExcelFilename + ";Extended Properties='Excel 12.0 XML;HDR=NO;IMEX=1;';";

            using (OleDbConnection conn = new OleDbConnection(connectionString))
                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = conn;

                // Get all Sheets in Excel File
                DataTable dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

                // Loop through all Sheets to get data
                foreach (DataRow dr in dtSheet.Rows)
                    string sheetName = dr["TABLE_NAME"].ToString();

                    if (!sheetName.EndsWith("$"))

                    // Get all rows from the Sheet. sExcelRange must be in the form A1:C10 or sim or just empty
                    cmd.CommandText = "SELECT * FROM [" + sheetName + sExcelRange + "]";

                    DataTable dt = new DataTable();
                    dt.TableName = sheetName;

                    OleDbDataAdapter da = new OleDbDataAdapter(cmd);


                cmd = null;

            return ds;

Tuesday, December 5, 2017

[C#] How to fix the "Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine" error

If you are trying to read an excel file in C# and you get this error:

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

You need to install "Microsoft Access Database Engine 2010 Redistributable" that is available at the Microsoft's website:

Wednesday, November 22, 2017

C# : How Convert doubles to strings ALWAYS with dots instead of commas

To convert a double to string ALWAYS with dots instead of commas (as it is used in some languages like Italian or German) you need to use an overloaded version of the ToString() method.


double dVal = 77.55;
string sVal = dVal.ToString(System.Globalization.CultureInfo.InvariantCulture);
// sVal will be  always "77.55"

or if you use System.Globalization

using System.Globalization;

double dVal = 77.55;
string sVal = dVal.ToString(CultureInfo.InvariantCulture);

Tuesday, November 21, 2017

How to implement Matlab-like Tic() and Toc() functions in C#

Tic() and Toc() functions are quite handy in Matlab and here is how you can get something similar in C#

using System;
using System.Diagnostics;

namespace MyTools
    class Perform
        static Stopwatch stopWatch;

        public static void Tic()
            stopWatch = new Stopwatch();


        public static void Toc()
            TimeSpan ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                ts.Hours, ts.Minutes, ts.Seconds,
                ts.Milliseconds / 10);

            // elapsed time since the last Tic()
            Console.WriteLine($"Elapsed time : {elapsedTime} ");


Now you can check the performance of your code with:


// some code that takes some time to execute


OR if you use the using static directive:

using static MyTools.Perform;


// some code that takes some time to execute


Happy programming!