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