C # Write chat program series notes (2) access the Mysql database

Source: Internet
Author: User

As a server, database operations are inevitable. How does C # perform operations? This program uses various methods in the MySQLDriverCS namespace. This is relatively simple, so the premise is that you need to install this stuff. After the installation is complete, there is an important step to reference it.

Right-click to reference

 

Select Add reference, find MySQLDriverCS. dll, and click OK.

Then use

using MySQLDriverCS;

 

In this way, you can use it.

The usage is as follows:

Define the link string

string connstr = "Data Source=chatsys;" +               "Password=root;User ID=root;Location=localhost;server=localhost;Charset=utf8";


Create link and open link

MySQLConnection conn = new MySQLConnection(connstr);            conn.Open();

 

Execute an operation

string cmd = "select * from t_userinfo where F_State=1";            sqlcmd = new MySQLCommand(cmd, conn);            MySQLDataReader anscmd = sqlcmd.ExecuteReaderEx();

 

If any result is returned, the result is as follows:

 

while (anscmd.Read())            {                               streamWriter[i].WriteLine((anscmd.GetString(anscmd.GetOrdinal("F_Name"))));                streamWriter[i].Flush();            }

 

In this way, we can operate MySQL Data.

Previous: http://www.bkjia.com/kf/201312/261981.html

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.