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

}

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.