C # operate MySql and PostgreSQL

Source: Internet
Author: User

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

}

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.