Tag Archives: C#

Create a MySQL table dynamically in C#

Sometimes you might need to create database tables dynamically, based on new users, products etc. The snippet below allows you to do exactly that, create a new table in your database dynamically, straight from your code.

This example is heavily based on How to connect to a MySQL database and retrieve data in C# as the same concept of connecting to the database is required.

The first thing you need to do, as mentioned in the article linked above, is that you will need to add a reference to MySQL.Data in your project. After you have done that, you can modify the snippet below to create the table with the columns you want based on your requirements.

If you are unsure as to which database engine to use, please take a look at https://dev.mysql.com/doc/refman/5.0/en/storage-engines.html as every database engine has different type of limitations, so it is better to choose the one that better suits your needs.

How to connect to a MySQL database and retrieve data in C#

Connecting to a MySQL database is fairly simple and straight forward. The first thing you will need to do is to add a reference to MySQL.Data in your project.

This can be done in a few ways:

  • Right click on references in your project -> click Manage NuGet packages -> Search and install MySQL.Data from Oracle
  • Open Package Manager Console from Tools -> NuGet Package Manager -> Paste in the console the following line: Install-Package MySql.Data
  • If you have installed the .NET Connector from MySQL you can navigate to where you have installed the connector and add a reference to the MySQL.Data.dll file

After you have added a reference to MySQL.Data you can tailor the snippet below to suit your requirements.

If you are interested in other type of databases you can check my Microsoft Access Database and SQLite database tutorials.

CLion is now available to download

JetBrains, the creators of many amazing tools for software developers released a new IDE called CLion.

CLion is a powerful IDE that can be used to develop C and C++ applications on Linux, OS X and Windows, enhancing your productivity with a smart editor, code quality assurance, automated refactorings, and deep integration with CMake build system. Moreover, CLion provides support for JavaScript, XML, HTML and CSS.

The main features of CLion consist of:
CMake – a build system that is used as a project model, which takes the information about your project from CMake files. All the changes are handled automatically and can be configured in Preferences.

An editor and one-click navigation to help you code easily:

  • Smart auto completion filters the suggestions to match the left value type.
  • Multiple cursors handle several editing tasks at a time.
  • Code auto formatting takes care of the preferred coding style guidelines.
  • Keyboard shortcuts help you select, rearrange and comment your code quickly.

Parameter info feature – can be used if you are unsure which function to use. It consists of all possible function signatures and parameters.

Fast project navigation – a very helpful feature which is included, as well as search abilities.

Code analysis – allows you to simply do even far-reaching changes, like renaming a symbol.

Integrated debugger – used for in-depth look into the execution of the code, providing a built-in debugger, able to add watches, evaluate expressions, change values and many more.

CLion integrates with popular version control systems, including Subversion, Git, GitHub, Mercurial, CVS, Perforce, and TFS.

Paid commercial and personal licenses are available at https://www.jetbrains.com/clion/buy/. If you are interested to try it out, there is a 30-day free trial version which you can download here.

If you are interested in learning more about CLion you can check out the guides and videos at https://www.jetbrains.com/clion/quickstart/.

Top 10 Most Popular Programming Languages 2014

With the end of 2014 approaching I was wondering what were the most popular programming languages of 2014 I decided to see if I can, somehow, get a satisfactory answer for my question.

Needless to say the chart below is nowhere near 100% accurate as there are a lot of variations for each tag. Moreover, it contains languages that might not be considered as programming languages, such as HTML, JavaScript etc and I have not added their frameworks in their count (example: JavaScript and JQuery). As you can imagine the data can be interpreted differently depending on how you want to parse the row data.

For my findings I used Stack Overflow’s database to query the posts that were created in 2014, then split and sorted the tags based on how many times they appeared in the posts. After parsing and processing 9307 unique tags with a total of 2591986 occurrences, these are the results.

Top 10 Most Popular Programming Languages 2014

Raw Data

Tag NameTag Count

Convert DateTime to Unix time in C#

I’ve been asked recently by a few people how to convert Unix time to DateTime format (and the other way around) so I decided to make a post about it explaining how Unix time works and provide a snippet to help people that want to convert DateTime to Unix time or vise versa.

Unix time is basically the number of seconds that have passed since 1/1/1970 00:00:00 (UTC). In order to convert a specific date and time to a Unix time value we will need to subtract the date above from the date we want to convert to Unix time.


Now if we want to convert a Unix time value to a DateTime object the the principle is the same. We take the 1/1/1970 00:00:00 (UTC) date and add the value of the Unix time as seconds to that date. The result would be the actual DateTime of the Unix time stamp.