Visual Studio community Connect to MySQL

Source: Internet
Author: User
Tags mysql for visual studio

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 
  1. Using System.Data.SqlClient;
  2. Using MySql.Data.MySqlClient;
  3. Connect to SQL Server
  4. /*
  5. String conn_str = @ "Connection string";
  6. String sql = "SQL command statement";
  7. SqlConnection conn = new SqlConnection (CONN_STR);
  8. SqlCommand cmd = new SqlCommand (SQL, conn);
  9. */
  10. Connect to MySQL
  11. String conn_str = @"connection string";
  12. String sql = "SQL command statement"; //"SELECT COUNT (*) from accounts where accounts= '" + TextBox1.Text + "'"
  13. Mysqlconnection conn = new Mysqlconnection (CONN_STR);
  14. Mysqlcommand cmd = new Mysqlcommand (Sql,conn);
  15. try{
  16. Conn. Open ();
  17. String result = cmd. ExecuteScalar (). ToString ();
  18. if (result!="0") {MessageBox.Show ("Find to" +result+"entry");}
  19. else {MessageBox.Show ("The account does not exist, please re-enter or register");}
  20. }
  21. Catch
  22. {
  23. throw;
  24. }
  25. finally {
  26. Conn. Close ();
  27. }

Visual Studio community Connect to MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.