* MySQL Data Provider
"Server=hostname;" + "Database=database;" + "User ID=username;" + "Password=password" (or) "host=hostname;" + "dbname=database;" + "user=username;" + "passwd=password"
using System; using System.Data; using Mono.Data.MySql; public class Test { public static void Main(string[] args) { string connectionString = "Server=localhost;" + "Database=test;" + "User ID=myuserid;" + "Password=mypassword;"; IDbConnection dbcon; dbcon = new MySqlConnection(connectionString); IDbCommand dbcmd = dbcon.CreateCommand(); // requires a table to be created named employee // with columns firstname and lastname // such as, // CREATE TABLE employee ( // firstname varchar(32), // lastname varchar(32)); string sql = "SELECT firstname, lastname " + "FROM employee"; dbcmd.CommandText = sql; IDataReader reader = dbcmd.ExecuteReader(); while(reader.Read()) { string FirstName = reader["firstname"]; string LastName = reader["lastname"]; Console.WriteLine("Name: " + FirstName + " " + LastName); } // clean up reader.Close(); reader = null; dbcmd.Dispose(); dbcmd = null; dbcon.Close(); dbcon = null; } }
mcs TestExample.cs \ -r System.Data.dll \ -r Mono.Data.MySql.dll
mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \ TestExample.cs \ -lib:C:/cygwin/home/MyHome/mono/install/lib \ -r System.Data.dll \ -r Mono.Data.MySql.dll
mono TestExample.exe
"Server=hostname;" + "Database=database;" + "User ID=username;" + "Password=password"
using System; using System.Data; using ByteFX.Data.MySQLClient; public class Test { public static void Main(string[] args) { string connectionString = "Server=localhost;" + "Database=test;" + "User ID=myuserid;" + "Password=mypassword;"; IDbConnection dbcon; dbcon = new MySQLConnection(connectionString); IDbCommand dbcmd = dbcon.CreateCommand(); // requires a table to be created named employee // with columns firstname and lastname // such as, // CREATE TABLE employee ( // firstname varchar(32), // lastname varchar(32)); string sql = "SELECT firstname, lastname " + "FROM employee"; dbcmd.CommandText = sql; IDataReader reader = dbcmd.ExecuteReader(); while(reader.Read()) { string FirstName = reader["firstname"]; string LastName = reader["lastname"]; Console.WriteLine("Name: " + FirstName + " " + LastName); } // clean up reader.Close(); reader = null; dbcmd.Dispose(); dbcmd = null; dbcon.Close(); dbcon = null; } }
mcs TestExample.cs -r System.Data.dll \ -r ByteFX.Data.dll
mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \ TestExample.cs \ -lib:C:/cygwin/home/MyHome/mono/install/lib \ -r System.Data.dll -r ByteFX.Data.dll
mono TestExample.exe