Create a winform Application:
Category Archives: Dotnet/C#
Now that you have installed Redis on your system, let’s jump to the actual coding using C#. If you wish to get the detailed procedures to install Redis, click here.
- Create a winform project in Visual Studio
- Install the nuget package by running the following command in the Package Manager Console
PM> Install-Package ServiceStack.Redis
Add a button and a button click event handler:
private void button1_Click(object sender, EventArgs e)
string elementKey = “TableId”;
using (var redisClient = new RedisClient(host, port, password))
if (redisClient.Get<string>(elementKey) == null)
// get value from the cache by key
var message = “Item value is: “ + redisClient.Get<string>(elementKey);
- Install the nuget package: in the nuget management console, type below line and run
Let’s create a class SqlUtils, and in the static constructor, type below code:
con = new MySqlConnection(connectionStr);
con.Open(); //open the connection
Console.WriteLine(“Successfully opened database.”);
catch (MySqlException err) //Catch MySql errors
Console.WriteLine(“Error: “ + err.ToString());
where the connection string is:
You might be interested in how to install MySQL in windows, check up this link for details.
- Run MySQL workbench after clicking Finish
In the MySQL workbench, copy below scripts to create a new database called “MyBooks”:
create database MyBooks
Select the above script line, then click the thunder icon to execute the sql statement
A new DB is created, as shown in the left DB group:
MySQL is a free database and can be easily used in your .Net Applications. This quick-start goes through the typical process that involves installation, up and running your “Hello MySQL” application.
If you are not interested in the MySQL installation, skip this and go directly to the below topics:
- Download MySQL server here or if you already had an oracle account, go directly here.
- Accept the license, and select the product/platform to download, click “Go”
- Download the installer
- Unzip and run the installer, follow the instructions.
- Select the options, in my case, I choose “Full”