. Net connection to MySQL

Source: Internet
Author: User
MySQL is a real multi-user, multi-thread SQL database server. SQL (Structured Query Language) is the world's most popular and standardized database language. MySQL
Is implemented by a Client/Server structure, which is guarded by a server Program Mysqld
And many different customer programs and libraries. However, this is quite popular in the * nix world. In the Windows world, especially for enterprise applications, or MS SQL
Server is dominant. Visual Studio of MS is not supported by native.

Recently, I have something to do on hand, which involves the MySQL database. I have never done anything based on MySQL before. I searched the internet and found many solutions. One of the methods is provided below. The rest will be studied on their own. First install MySQL connector/net, which is a MySQL ADO. Net driver. After installation, you can easily operate the MySQL database.


ConnectionCodeSimple
VB. NET

 
'Introduce MySQL
 
ImportsMySQL. Data. mysqlclient
 
 
Private SubConnectbtn_click (ByvalSenderAsSystem.Object,ByvalEAsSystem. eventargs)HandlesConnectbtn. Click
 
DimConnstrAs String
 
DimConnAsMysqlconnection
 
 
 
If NotConnIs Nothing ThenConn. Close ()
Connstr =String. Format ("Server = {0}; user id = {1}; Password = {2}; database = MySQL; pooling = false",_
 
Server. Text, userid. Text, password. Text)
 
 
 
Try
 
Conn =NewMysqlconnection (connstr)
 
Conn. open ()
 
 
 
Getdatabases ()
 
CatchExAsMysqlexception
 
MessageBox. Show ("Error connecting to the server :"+ Ex. Message)
 
End Try
 
EndSub

C #

 
UsingMySQL. Data. mysqlclient;
Private   Void Connectbtn_click ( Object Sender, eventargs E)
{
String Connstr =   " Server = localhost; user id = root; Password = Mick; database = MySQL; pooling = false " ;

Mysqlconnection myconn= NewMysqlconnection (connstr );
Try
{
Myconn. open ();

Mysqldataadapter da =   New Mysqldataadapter ( " Select * From help_category " , Myconn );
Datatable dt =   New Datatable ();
Da. Fill (DT );
Datagridview1.datasource = DT;
}
Catch (Mysqlexception exc)
{
MessageBox. Show (EXC. Message );
}
Finally
{
Myconn. Close ();
}
}

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.