How to connect mysql to visual studio using c# language

First you must download mysql connector , and to know how to use that , visit this link How to connect mysql with visual studio

The Code is below
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient ;
namespace WindowsFormsApplication1
    public partial class Form1 : Form
        string connection = “server=localhost; user=root; database=dbsiswa; “;
        MySqlConnection conn = new MySqlConnection();
        MySqlCommand command = new MySqlCommand();
        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            MySqlConnection conn = new MySqlConnection(connection);
            MySqlCommand command = conn.CreateCommand();

            try {
                MessageBox.Show(“KOneksi Berhasil”);}
                catch (Exception ex){
                MessageBox .Show (“Koneksi Gagal”);

Leave a Reply