C # MySQL connection

Source: Internet
Author: User
C # MySQL connection
  • Mysqlconnection conn = NULL;
  • Try
  • {
  • // Mysqlconnection conn = new mysqlconnection (New mysqlconnectionstring ("myquest", "root", "amttgroup"). asstring );
  • // Instantiate a connection object. myquest is the database name, root is the database username, and amttgroup is the database password.
  • String connstr = "Data Source = MySQL; Password = root; user id = root; location = localhost ";
  • Conn = new mysqlconnection (constr );
  • Conn. open ();
  • String query = "insert into test. dbtable values (10, 'disksidkfsdi ', 'asdfaf', 'adsfasdf ')";
  • String TMP = NULL;
  • Mysqlcommand cmd = new mysqlcommand (query, Conn );
  • For (INT I = 0; I <100000; I ++)
  • {
  • Cmd. executenonquery ();
  • }
  • Cmd. Dispose ();
  • Conn. Close ();
  • Query = "select * from test. dbtable ";
  • Mysqlcommand cmd2 = new mysqlcommand (query, Conn );
  • Conn. open ();
  • // Set Chinese output
  • Mysqlcommand firstcmd = new mysqlcommand ("set names gb2312", myconn );
  • Firstcmd. executenonquery ();
  • Mysqldatareader reader = pai2.executereaderex ();
  • While (reader. Read ())
  • {
  • TMP = reader [0]. tostring ();
  • TMP = reader [1]. tostring ();
  • TMP = reader [2]. tostring ();
  • TMP = reader [3]. tostring ();
  • }
  • Conn. Close ();
  • Query = "delete from test. dbtable ";
  • Mysqlcommand cmd3 = new mysqlcommand (query, Conn );
  • Conn. open ();
  • Statement 3.executenonquery ();
  • }
  • Catch (exception ex)
  • {
  • MessageBox. Show (ex. Message );
  • }
  • Finally
  • {
  • Conn. Close ();
  • }
  • Mysqlconnection conn = NULL;
  • Try
  • {
  • // Mysqlconnection conn = new mysqlconnection (New mysqlconnectionstring ("myquest", "root", "amttgroup"). asstring );
  • // Instantiate a connection object. myquest is the database name, root is the database username, and amttgroup is the database password.
  • String connstr = "Data Source = MySQL; Password = root; user id = root; location = localhost ";
  • Conn = new mysqlconnection (constr );
  • Conn. open ();
  • String query = "insert into test. dbtable values (10, 'disksidkfsdi ', 'asdfaf', 'adsfasdf ')";
  • String TMP = NULL;
  • Mysqlcommand cmd = new mysqlcommand (query, Conn );
  • For (INT I = 0; I <100000; I ++)
  • {
  • Cmd. executenonquery ();
  • }
  • Cmd. Dispose ();
  • Conn. Close ();
  • Query = "select * from test. dbtable ";
  • Mysqlcommand cmd2 = new mysqlcommand (query, Conn );
  • Conn. open ();
  • // Set Chinese output
  • Mysqlcommand firstcmd = new mysqlcommand ("set names gb2312", myconn );
  • Firstcmd. executenonquery ();
  • Mysqldatareader reader = pai2.executereaderex ();
  • While (reader. Read ())
  • {
  • TMP = reader [0]. tostring ();
  • TMP = reader [1]. tostring ();
  • TMP = reader [2]. tostring ();
  • TMP = reader [3]. tostring ();
  • }
  • Conn. Close ();
  • Query = "delete from test. dbtable ";
  • Mysqlcommand cmd3 = new mysqlcommand (query, Conn );
  • Conn. open ();
  • Statement 3.executenonquery ();
  • }
  • Catch (exception ex)
  • {
  • MessageBox. Show (ex. Message );
  • }
  • Finally
  • {
  • Conn. Close ();
  • }
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.