This article describes the actual application code of C # connecting to the MySQL database. If you are interested in the actual operation steps of C # connecting to the MySQL database, you can get a better understanding of the following articles.
- {
- String sqlstr = "select * from manavatar ";
- MySQL (the best combination with PHP) Connection DBConn = new MySQL (the best combination with PHP) Connection
(New MySQL (best combination with PHP) ConnectionString ("192.168.0.13", "flashdata", "root", "root", 3306). AsString );
- DBConn. Open ();
- // MySQL (the best combination with PHP) DataAdapter myadap = new MySQL (the best combination with PHP) DataAdapter (sqlstr, conn );
- MySQL (the best combination with PHP) Command DBComm = new MySQL (the best combination with PHP) Command (sqlstr, DBConn );
- MySQL (the best combination with PHP) DataReader DBReader = DBComm. ExecuteReaderEx (); // DBComm. ExecuteReaderEx ();
- MySQL (the best combination with PHP) DataAdapter DTAdapter = new MySQL (the best combination with PHP) DataAdapter (sqlstr, DBConn );
- DataSet myDataSet = new DataSet ();
- DTAdapter. Fill (myDataSet, "manavatar ");
- Try
- {
- While (DBReader. Read ())
- {
- // Console. WriteLine ("11 ");
- Console. WriteLine ("DBReader: {0}, \ t \ tddddd: {1}, \ t {2}", DBReader. GetString (0 ),
DBReader. GetString (1), DBReader. GetString (3 ));
- }
- Console. WriteLine ("0000 ");
- }
- Catch (Exception e)
- {
- Console. WriteLine ("failed to read! "+ E. ToString ());
- }
- Finally
- {
- Console. WriteLine ("DBReader disabled ");
- Console. WriteLine ("DBConn disabled ");
- DBReader. Close ();
- // DBConn. Close ();
- }
- For (int I = 0; I <myDataSet. Tables ["manavatar"]. Rows. Count; I ++)
- {
- Console. WriteLine ("{0}", myDataSet. Tables ["manavatar"]. Rows [2] ["user"]);
- }
- }
This is a simple example.
There is a problem here: if dataset does not set a primary key, it may cause some log library operation problems, such as updata errors.
The above content is an introduction to connecting C # to MySQL. I hope you will get some benefits.