// 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 System.Drawing; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace DefaultNamespace { public class MainForm : Form { private MySqlConnection con; private Button btnHent; private RichTextBox rtbHent; private Button btnGem; private RichTextBox rtbGem; public MainForm() { InitializeComponent(); con = new MySqlConnection("Database=Test;Data Source=localhost;User Id=;Password="); con.Open(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } private void InitializeComponent() { rtbGem = new RichTextBox(); btnGem = new Button(); rtbHent = new RichTextBox(); btnHent = new Button(); SuspendLayout(); rtbGem.Location = new Point(25, 25); rtbGem.Name = "rtbGem"; rtbGem.TabIndex = 0; rtbGem.Text = ""; btnGem.Location = new Point(175, 25); btnGem.Name = "btnGem"; btnGem.TabIndex = 2; btnGem.Text = "Gem i DB"; btnGem.Click += new System.EventHandler(BtnGemClick); rtbHent.Location = new Point(25, 150); rtbHent.Name = "rtbHent"; rtbHent.TabIndex = 1; rtbHent.Text = ""; btnHent.Location = new Point(175, 150); btnHent.Name = "btnHent"; btnHent.TabIndex = 3; btnHent.Text = "Hent fra DB"; btnHent.Click += new System.EventHandler(BtnHentClick); AutoScaleBaseSize = new Size(5, 10); ClientSize = new Size(300, 275); Controls.Add(btnHent); Controls.Add(btnGem); Controls.Add(rtbHent); Controls.Add(rtbGem); Name = "MainForm"; Text = "Gem og hent test"; ResumeLayout(false); } void BtnGemClick(object sender, System.EventArgs e) { MySqlCommand ins = new MySqlCommand("INSERT INTO rtftest VALUES(1,?RTFTXT)", con); ins.Parameters.Add(new MySqlParameter("?RTFTXT", rtbGem.Rtf)); ins.ExecuteNonQuery(); } void BtnHentClick(object sender, System.EventArgs e) { MySqlCommand sel = new MySqlCommand("SELECT rtf FROM rtftest WHERE id=1", con); String res = (String)sel.ExecuteScalar(); rtbHent.Rtf = res; } } }