Click here to Skip to main content
15,896,557 members
Articles / Desktop Programming / Windows Forms

Working C# code for MySql Stored Procedures IN, OUT, and INOUT parameters

Rate me:
Please Sign up or sign in to vote.
4.29/5 (10 votes)
15 May 2009CPOL9 min read 179.4K   3.5K   42  
An article on how to get parameters into and out of MySql stored procedures.
namespace StoredProcs
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.CreateTable = new System.Windows.Forms.Button();
            this.DropProc = new System.Windows.Forms.Button();
            this.CreateProc = new System.Windows.Forms.Button();
            this.spInsert = new System.Windows.Forms.Button();
            this.proc2 = new System.Windows.Forms.Button();
            this.txtTable = new System.Windows.Forms.TextBox();
            this.txtDropProc = new System.Windows.Forms.TextBox();
            this.txtCreateProc = new System.Windows.Forms.TextBox();
            this.txtInsert = new System.Windows.Forms.TextBox();
            this.txtProc2 = new System.Windows.Forms.TextBox();
            this.txtConcat = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // CreateTable
            // 
            this.CreateTable.Location = new System.Drawing.Point(0, 21);
            this.CreateTable.Name = "CreateTable";
            this.CreateTable.Size = new System.Drawing.Size(104, 23);
            this.CreateTable.TabIndex = 0;
            this.CreateTable.Text = "Create Table";
            this.CreateTable.UseVisualStyleBackColor = true;
            this.CreateTable.Click += new System.EventHandler(this.CreateTable_Click);
            // 
            // DropProc
            // 
            this.DropProc.Location = new System.Drawing.Point(0, 64);
            this.DropProc.Name = "DropProc";
            this.DropProc.Size = new System.Drawing.Size(104, 23);
            this.DropProc.TabIndex = 1;
            this.DropProc.Text = "Drop Procedure";
            this.DropProc.UseVisualStyleBackColor = true;
            this.DropProc.Click += new System.EventHandler(this.DropProc_Click);
            // 
            // CreateProc
            // 
            this.CreateProc.Location = new System.Drawing.Point(0, 110);
            this.CreateProc.Name = "CreateProc";
            this.CreateProc.Size = new System.Drawing.Size(104, 23);
            this.CreateProc.TabIndex = 2;
            this.CreateProc.Text = "Create Proc";
            this.CreateProc.UseVisualStyleBackColor = true;
            this.CreateProc.Click += new System.EventHandler(this.CreateProc_Click);
            // 
            // spInsert
            // 
            this.spInsert.Location = new System.Drawing.Point(0, 154);
            this.spInsert.Name = "spInsert";
            this.spInsert.Size = new System.Drawing.Size(104, 23);
            this.spInsert.TabIndex = 3;
            this.spInsert.Text = "Insert";
            this.spInsert.UseVisualStyleBackColor = true;
            this.spInsert.Click += new System.EventHandler(this.spInsert_Click);
            // 
            // proc2
            // 
            this.proc2.Location = new System.Drawing.Point(0, 197);
            this.proc2.Name = "proc2";
            this.proc2.Size = new System.Drawing.Size(104, 23);
            this.proc2.TabIndex = 4;
            this.proc2.Text = "Run Proc2";
            this.proc2.UseVisualStyleBackColor = true;
            this.proc2.Click += new System.EventHandler(this.proc2_Click);
            // 
            // txtTable
            // 
            this.txtTable.Location = new System.Drawing.Point(124, 24);
            this.txtTable.Name = "txtTable";
            this.txtTable.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
            this.txtTable.Size = new System.Drawing.Size(156, 20);
            this.txtTable.TabIndex = 5;
            // 
            // txtDropProc
            // 
            this.txtDropProc.Location = new System.Drawing.Point(124, 67);
            this.txtDropProc.Name = "txtDropProc";
            this.txtDropProc.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
            this.txtDropProc.Size = new System.Drawing.Size(156, 20);
            this.txtDropProc.TabIndex = 6;
            // 
            // txtCreateProc
            // 
            this.txtCreateProc.Location = new System.Drawing.Point(124, 113);
            this.txtCreateProc.Name = "txtCreateProc";
            this.txtCreateProc.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
            this.txtCreateProc.Size = new System.Drawing.Size(156, 20);
            this.txtCreateProc.TabIndex = 7;
            // 
            // txtInsert
            // 
            this.txtInsert.Location = new System.Drawing.Point(124, 157);
            this.txtInsert.Name = "txtInsert";
            this.txtInsert.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
            this.txtInsert.Size = new System.Drawing.Size(156, 20);
            this.txtInsert.TabIndex = 8;
            // 
            // txtProc2
            // 
            this.txtProc2.Location = new System.Drawing.Point(124, 200);
            this.txtProc2.Name = "txtProc2";
            this.txtProc2.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
            this.txtProc2.Size = new System.Drawing.Size(156, 20);
            this.txtProc2.TabIndex = 9;
            // 
            // txtConcat
            // 
            this.txtConcat.Location = new System.Drawing.Point(0, 244);
            this.txtConcat.Name = "txtConcat";
            this.txtConcat.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
            this.txtConcat.Size = new System.Drawing.Size(280, 20);
            this.txtConcat.TabIndex = 10;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(121, 184);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(121, 13);
            this.label1.TabIndex = 11;
            this.label1.Text = "Inserted auto_increment";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(-3, 228);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(137, 13);
            this.label2.TabIndex = 12;
            this.label2.Text = "INOUT concatenated fields";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtConcat);
            this.Controls.Add(this.txtProc2);
            this.Controls.Add(this.txtInsert);
            this.Controls.Add(this.txtCreateProc);
            this.Controls.Add(this.txtDropProc);
            this.Controls.Add(this.txtTable);
            this.Controls.Add(this.proc2);
            this.Controls.Add(this.spInsert);
            this.Controls.Add(this.CreateProc);
            this.Controls.Add(this.DropProc);
            this.Controls.Add(this.CreateTable);
            this.Name = "Form1";
            this.Text = "MySql Stored Procedures Demo";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button CreateTable;
        private System.Windows.Forms.Button DropProc;
        private System.Windows.Forms.Button CreateProc;
        private System.Windows.Forms.Button spInsert;
        private System.Windows.Forms.Button proc2;
        private System.Windows.Forms.TextBox txtTable;
        private System.Windows.Forms.TextBox txtDropProc;
        private System.Windows.Forms.TextBox txtCreateProc;
        private System.Windows.Forms.TextBox txtInsert;
        private System.Windows.Forms.TextBox txtProc2;
        private System.Windows.Forms.TextBox txtConcat;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Senior software developer / consultant with 30 years experience.

Comments and Discussions