// Example Database.cs // This example requires: // * MySQL-ODBC driver 3.51 installed on the local PC // * A MySQL database server on host sql.dina.kvl.dk with a database // test containing a table Message declared like this: // CREATE TABLE Message // (name VARCHAR(80), // msg VARCHAR(200), // severity INT); // * It may be necessary to change the .Net security settings if this // is to be run from a network drive. // Use Start | Settings | Control Panel | Administration // | .Net Security blah blah using System; using System.Data.Odbc; // OdbcConnection OdbcCommand OdbcDataReader using System.Collections.Generic; // List class Database { public static void Main(String[] args) { String setup = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=sql.dina.kvl.dk;" + "DATABASE=test;" + "UID=sestoft;" + "PASSWORD=........;"; using (OdbcConnection conn = new OdbcConnection(setup)) { conn.Open(); String query = "SELECT name, msg, severity FROM Message ORDER BY name"; OdbcCommand cmd = new OdbcCommand(query, conn); OdbcDataReader r = cmd.ExecuteReader(); while (r.Read()) { String name = r.GetString(0); String msg = r.GetString(1); int severity = r.GetInt32(2); Console.WriteLine("{0}: {1} ({2})", name, msg, severity); } r.Close(); } } }