We are all familiar with MySQL, and PostgreSQL is not so famous. in fact, they are two similar relational databases. postgreSQL was originally named Postgres. After some improvements, it was renamed PostgreSQL. for details, visit the official website.
MySQL Official Website: http://www.mysql.com/
PostgreSQL Website: http://www.postgresql.org/
After installing MySQL, there is generally no default graphic operation interface, but you can download a graphical tool MySQL workbench.
PostgreSQL has a built-in graphical interface tool pgadmin III.
When you get used to Windows, you always want to perform operations on the graphic interface. If Linux is used more often, UNIX will not rely on the graphic interface.
C # operate MySQL
Similar to operating other databases, you must first download the corresponding DLL.
MySQL. Data. mysqlclient. dll
Then add reference. Reference namespace
Using mysql. Data. mysqlclient;
String connectstring = @ "Server = localhost; userid = root; Password = Arwen; database = test";/* because my database uses localhost locally, can be replaced with an IP address */
Mysqlconnection conn = new mysqlconnection (connectstring );
Conn. open ();
Mysqlcommand cmd = conn. createcommand ();
Cmd. commandtext = "select * from Info ";
Cmd. commandtype = commandtype. text;
Using (mysqldatareader reader = cmd. executereader ())
{
While (reader. Read ())
Console. writeline (Reader [0]. tostring ());
}
C # PostgreSQL operations
Go to the entire file named PostgreSQL. Data. postgresqlclient. dll.
Add reference and use namespace
Using PostgreSQL. Data. postgresqlclient;
String connectstring = @ "Server = localhost; database = s; user id = Arwen; Password = Arwen ";
Pgconnection conn = new pgconnection (connectstring );
Conn. open ();
Pgcommand cmd = conn. createcommand ();
Cmd. commandtext = "select * from test ";
Cmd. commandtype = commandtype. text;
Using (pgdatareader reader = cmd. executereader ())
{
While (reader. Read ())
Console. writeline (Reader [0]. tostring ());
}