Connecting MySQL with Visual Studio C#

前端 未结 5 511
情歌与酒
情歌与酒 2020-12-18 08:01

I\'m new to MySQL Workbench and I\'m trying to make a Timekeeping system. I\'m wondering how to connect MySQL with Visual Studio C#?

5条回答
  •  感动是毒
    2020-12-18 08:37

    If you are working with MySQL for the first time in your PC, do these things.

    1. Install MySQL Server (Link here) - 28 MB
    2. Install MySQL ODBC Connector (Link here) - 3 MB

    Now install SqlYog Community Edition. ( Link here ). You can manipulate your MySQL Databases using this.

    Now in AppSettings of web.config, set two entries like this.

    
      
        
        
      
    
    

    And call it like in your MySQL class like this.

    public string MyConnectionString 
    {
        get
        {
            //return {MySQL ODBC 5.1 Driver};Server=localhost;Database=mydatabase;uid=root;pwd=;Option=3;
            return ConfigurationManager.AppSettings["ODBCDriver"]
                + ConfigurationManager.AppSettings["DataBaseDetails"];
        }
    }
    

    Now you can initialize your connection like this.

    OdbcConnection connection = new OdbcConnection(MyConnectionString);
    

    Namespace imported

    using System.Data.Odbc;
    

    Hope you get the idea.

提交回复
热议问题