Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

To connect vs2015 to mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the steps of connecting vs2015 to mysql, which has certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

How does vs2015 connect to mysql?

1. To create a new project called mysql, select the windows in the programming environment, and then select the windows forms application to create a new form to display the dataset queried to the sql database

two。 Drag a button and a datagridview control from the toolbox to the form1 form. The button triggers the connection to the database to get the dataset. The name of the button is display, and the datagridview control is used to display the contents of the dataset.

3. Click the reference folder in solution Explorer and then right-click to add reference, and select browse to open mysql.data.dll. This is a dynamic library for c # to connect to the mysql database, which encapsulates many commonly used methods to manipulate the database.

4. Add using MySql.Data.MySqlClient; to the code of form1.cs in solution Explorer, which is the actual reference to mysql.data.dll in the code. With this c #, you can easily operate the sql database.

5. Add the following code to the click event of the button

String str = "Server=127.0.0.1;User ID=root;Password=123456;Database=test;CharSet=gbk;"; MySqlConnection con = new MySqlConnection (str); / / instantiation link con.Open (); / / Open connection string strcmd = "select * from user"; MySqlCommand cmd = new MySqlCommand (strcmd, con); MySqlDataAdapter ada = new MySqlDataAdapter (cmd); DataSet ds = new DataSet () Ada.Fill (ds); / / query results populate the dataset dataGridView1.DataSource = ds.Tables [0]; con.Close (); / / close the connection

6. Use the navicat software to create a new table user in the database test, and then create two new fields username and password (the field in the figure). Navicat software is a graphical interface tool for mysql, which is responsible for database operations such as new tables and backups, and operates intuitively through the interface.

7. After the database is built, you can execute the project. Click the display button to execute the result as follows. The appearance of username and password indicates that the database connection is successful. The following is empty because no data has been added.

Thank you for reading this article carefully. I hope it will be helpful for everyone to share the steps of connecting vs2015 to mysql. At the same time, I also hope you can support us, pay attention to the industry information channel, and find out if you have any problems. Detailed solutions are waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report