How to connect to mysql in vs2015?
1. Create a new project named mysql, select c# for the programming environment, then select the windows form application, and create a new form to display the data set queried to the sql database
2. Drag a button and datagridview control from the toolbox to the form1 form. The button is to trigger the connection to the database to obtain the data set. The name of the button is display, and the datagridview control is used to Display the contents of the data set
string str = "Server=127.0.0.1;User ID=root;Password=123456;Database=test;CharSet=gbk;"; MySqlConnection con = new MySqlConnection(str);//实例化链接 con.Open();//开启连接 string strcmd = "select * from user"; MySqlCommand cmd = new MySqlCommand(strcmd, con); MySqlDataAdapter ada = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); ada.Fill(ds);//查询结果填充数据集 dataGridView1.DataSource = ds.Tables[0]; con.Close();//关闭连接
##Related learning recommendations:mysql tutorial(video)
The above is the detailed content of How to connect to mysql in vs2015?. For more information, please follow other related articles on the PHP Chinese website!