Mono Develop – Use .net MySql connector

source-codeA short example on how to use the .net MySql connector with Mono Develop.
First you need to make it available to your project.
Go to Project -> Edit References
Select the .Net Assembly tab. Then Navigate to your folder containing Mysql.Data.dll and select the file, and press ok.

Here is a short example program on how to insert a record into a test MySql database.

[sourcecode language=”csharp”]
using System;
using MySql.Data.MySqlClient;

namespace testmysql
class MainClass
public static void Main (string[] args)
// First a few variables, Assuming MySQL server is at and default port 3306
string cs = @"server=;port=3306;userid=testuser;password=testpass;database=testdb";
MySqlConnection myCon = null;
MySqlCommand myCmd = null;
Console.WriteLine ("Welcome to Test MySQL….");
// create mysql connector, and connect
Console.WriteLine("creating mysql connector…");
myCon = new MySqlConnection(cs);
// Create a sql string with sample data, inserted to testtable
string strQuery = "INSERT INTO testdb.testtable(testdata) values (‘Sample Data #1’);";
// Execute
myCmd = new MySqlCommand(strQuery, myCon);
// Close connection
Console.WriteLine("Data inserted to MySQL database successfully");

Happy programming!

Have any Question or Comment?

Leave a Reply