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 ();
}
}