Using visual studio C# you can connect to mysql in three simple steps. Here we go
- Before we start writing the code, we need to add the
mysql
Reference in our project. To do so, we right click our project name, and choose Add Reference:
- Then we choose MySql.Data from the list:
Lets confirm it
//Add MySql Library using MySql.Data.MySqlClient; class DBConnect { private MySqlConnection connection; private string server; private string database; private string uid; private string password; //Constructor public DBConnect() { Initialize(); } //Initialize values private void Initialize() { server = "localhost"; database = "connectcsharptomysql"; uid = "username"; password = "password"; string connectionString; connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";"; connection = new MySqlConnection(connectionString); } //open connection to database private bool OpenConnection() { } //Close connection private bool CloseConnection() { } //Insert statement public void Insert() { } //Update statement public void Update() { } //Delete statement public void Delete() { } //Select statement public List <string> [] Select() { } //Count statement public int Count() { } //Backup public void Backup() { } //Restore public void Restore() { } }
Enjoy!