// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using MySql.Data.MySqlClient; class MainClass { public static void Main(string[] args) { MySqlConnection con = new MySqlConnection("Database=Test;Data Source=localhost;User Id=;Password="); con.Open(); MySqlCommand cre = new MySqlCommand("CREATE TABLE temptest (id VARCHAR(20) PRIMARY KEY)", con); cre.ExecuteNonQuery(); MySqlCommand ins = new MySqlCommand("INSERT INTO temptest VALUES (?id)", con); ins.Parameters.Add("?id", MySqlDbType.VarChar, 20); ins.Parameters["?id"].Value = "Dette er en test"; //ins.Parameters.Add("?id", MySqlDbType.VarChar, 20).Value = "Dette er en test"; ins.ExecuteNonQuery(); MySqlCommand sel = new MySqlCommand("SELECT * FROM temptest", con); MySqlDataReader rdr = sel.ExecuteReader(); while(rdr.Read()) { string id = (string)rdr[0]; Console.WriteLine(id); } rdr.Close(); MySqlCommand drp = new MySqlCommand("DROP TABLE temptest", con); drp.ExecuteNonQuery(); con.Close(); } }