Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
This article started in csdn:http://blog.csdn.net/cxq2046/article/details/51108256 so far has not authorized any other platform to publish.
Visual Studio community connected to MySQL, the steps are simple, but when you just got a face, now record as follows to make a memo:
After installing VS2015 and MySQL, only need to install two more things.
One is sdk:mysql for Visual Studio
: http://www.mysql.com/why-mysql/windows/visualstudio/
The other is the drive: Mysql Connector
Choose different connector according to different languages.
: http://www.mysql.com/products/connector/
After restarting VS2015, right-click on the menu bar or toolbar to see the item "MySQL" On the right-click menu, and the toolbar will appear with the MySQL-related tool button. These tools can visualize the operation of the MySQL database.
In the case of MySQL running, you can
Left sidebar: Server Explorer → data connections → right-click add link
Or
Menu bar: "Tools" → "Connect to Database"
Connect to MySQL.
Take the C # form program as an example, pull the DataGridView control into the form, set the "DataSource" property of the data, bind the database, and display the datasheet in a grid format.
The following is an example of code that connects to a database:
[CSharp]View PlainCopy
- Using System.Data.SqlClient;
- Using MySql.Data.MySqlClient;
- Connect to SQL Server
- /*
- String conn_str = @ "Connection string";
- String sql = "SQL command statement";
- SqlConnection conn = new SqlConnection (CONN_STR);
- SqlCommand cmd = new SqlCommand (SQL, conn);
- */
- Connect to MySQL
- String conn_str = @"connection string";
- String sql = "SQL command statement"; //"SELECT COUNT (*) from accounts where accounts= '" + TextBox1.Text + "'"
- Mysqlconnection conn = new Mysqlconnection (CONN_STR);
- Mysqlcommand cmd = new Mysqlcommand (Sql,conn);
- try{
- Conn. Open ();
- String result = cmd. ExecuteScalar (). ToString ();
- if (result!="0") {MessageBox.Show ("Find to" +result+"entry");}
- else {MessageBox.Show ("The account does not exist, please re-enter or register");}
- }
- Catch
- {
- throw;
- }
- finally {
- Conn. Close ();
- }
Visual Studio community Connect to MySQL