C # How to connect MySQL database

Source: Internet
Author: User

1. To connect to the MySQL database, you must first download the MySQL connection. net file,

File is http://download.csdn.net/detail/xiaoliu123586/9145579
2, unzip the Mysql-connector-net-6.6.6-noinstall.zip file just downloaded, there are several versions of the choice, here I choose V4,

Select a few files from all the files in the V4.0 and add them to the reference of the C # project, and then you can write the program to do the database.

3. Database Operation code InsertMySql.cs

1 usingSystem;2 usingSystem.Collections;3 usingSystem.Configuration;4 usingMysql.data;5 usingMySql.Data.MySqlClient;6 usingSystem.Data;7 8 namespacetest19 {Ten     class Program One     { A           Public Static voidMain (string[] args) -         { -             stringConstr="Server=localhost; User Id=root;password=admin;database=haha"; theMysqlconnection mycon=Newmysqlconnection (constr); - Mycon. Open (); -Mysqlcommand myCMD =NewMysqlcommand ("INSERT INTO User (Id,name) VALUES (' 3 ', ' Ooooss ')", mycon); -             if(myCMD. ExecuteNonQuery () >0) +             { -Console.WriteLine ("Data inserted successfully! "); +             } A console.readline (); at Mycon. Close (); -         } -     } -}

C # How to connect MySQL database

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.