Click here to Skip to main content
12,447,625 members (59,145 online)
Click here to Skip to main content
Articles » Database » Database » MySQL » Downloads

Stats

111.2K views
2.9K downloads
40 bookmarked
Posted

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

, 15 May 2009 CPOL
An article on how to get parameters into and out of MySql stored procedures.
ScreenShot.png
StoredProcs
bin
Debug
BinaryLib.dll
BinaryLib.pdb
StoredProcs.exe
StoredProcs.pdb
StoredProcs.vshost.exe
obj
Debug
Refactor
StoredProcs.csproj.GenerateResource.Cache
StoredProcs.exe
StoredProcs.Form1.resources
StoredProcs.pdb
StoredProcs.Properties.Resources.resources
TempPE
Properties
StoredProcs.suo
StoredProcs.sln.cache
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace StoredProcs
{
    public partial class Form1 : Form
    {
        clsKenTest ken;
        string ans;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ken = new clsKenTest("server=localhost;userid=demo;database=test;pooling=true");
        }
        private string go(string sql)
        {
            try
            {
                return ken.ExecSql(sql);
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message);
                return ex.Message;
            }
        }

        private void CreateTable_Click(object sender, EventArgs e)
        {
            ans = go(ken.table);
            txtTable.Text = ans;
        }

        private void DropProc_Click(object sender, EventArgs e)
        {
            ans = go(ken.drop);
            txtDropProc.Text = ans;
        }

        private void CreateProc_Click(object sender, EventArgs e)
        {
            ans = go(ken.proc);
            txtCreateProc.Text = ans;
        }

        private void spInsert_Click(object sender, EventArgs e)
        {
            ans = ken.DoInsert(ken.nsert);
            txtInsert.Text = ans;
        }

        private void proc2_Click(object sender, EventArgs e)
        {
            ans = ken.runProc();
            if (ans.Equals("OK"))
            {
                txtProc2.Text = ken.lastinsertid.ToString();
                txtConcat.Text = ken.newval;
            }
            else
            {
                txtProc2.Text = ans;
                txtConcat.Text = "Error";
            }
        }
    }
}

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)

Share

About the Author

ken.tachyon
Web Developer
United States United States
Senior software developer / consultant with 30 years experience.

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160811.3 | Last Updated 15 May 2009
Article Copyright 2009 by ken.tachyon
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid