C# - Using MySQL Stored Procedure

call stored procedure in c#

How To Use MySQL Stored Procedure In C#

                                                                                                                         

In This C# Tutorial  We Will See How To Call MySQL Stored Procedure Using CSharp Programming Language.


Project Source Code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Csharp_And_MySQL
{
    public partial class Using_MySQL_Stored_Procedures : Form
    {
        public Using_MySQL_Stored_Procedures()
        {
            InitializeComponent();
        }

        MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;Initial Catalog='test_db';username=root;password=");
        
        private void BTN_ADD_Click(object sender, EventArgs e)
        {
            MySqlParameter[] pms = new MySqlParameter[3];
            pms[0] = new MySqlParameter("fn", MySqlDbType.VarChar);
            pms[0].Value = textBoxFName.Text;

            pms[1] = new MySqlParameter("ln", MySqlDbType.VarChar);
            pms[1].Value = textBoxLName.Text;

            pms[2] = new MySqlParameter("age", MySqlDbType.Int32);
            pms[2].Value = textBoxAge.Text;

            MySqlCommand command = new MySqlCommand();

            command.Connection = connection;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "SP_ADD_USER";

            command.Parameters.AddRange(pms);

            connection.Open();
            if(command.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Yes");
            }
            else
            {
                MessageBox.Show("No");
            }
            connection.Close();

        }
    }
}

      
///////////////OUTPUT:

using mysql stored procedure in c#








Share this

Related Posts

Previous
Next Post »