Skip to main content

create stoared procedure in C#


Following is the project in C# which creates a stoared procedure in mysql database.
for that we created a class library and we import this in one windows project.



using MySql.Data.MySqlClient;
using System.Data;

namespace stored_proc_db_disp_dll
{
    public class Class1
    {
        MySqlConnection con = new MySqlConnection("server=localhost;uid=root;pwd=root;database=test");
        MySqlCommand cmd=null;

        MySqlDataReader dr;

        public Boolean createprocedure(String str)
        {
            bool b = true;
            try
            {
                cmd.CommandText = str;

                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                b = false;
            }
            return b;
        }
}
}




using stored_proc_db_disp_dll;

namespace create_procedure_demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Class1 c1 = new Class1();
            if (c1.createprocedure(textBox1.Text))
            {
                MessageBox.Show("Procedure created ");
            }
            else
            {
                MessageBox.Show("Can not creaye procedure");
            }

        }
}
}

Comments