I'm new in c#, i stared learning about 2 mouths ago.Now i wanna to share some tips i learned.Let's start
Likes the title, very simple so i got a trouble when trying connect to mysql without mysql driver.i spent a night to solve.
First go to http://dev.mysql.com/downloads/connector/net/#downloads to download last version. Before installing, go to folder root\MySQL\MySQL Connector Net 5.0.9\Binaries\.NET 2.0,you will see a file named: MySql.Data.dll that is mysql driver. Or you can download from my direct link Mysql.Data.dll
open Visual Studio, do following



import MySql.Data.MySqlClient
Boolean rs = false;
String conn = "SERVER=127.0.0.1;DATABASE=MoodleService;UID=root;PASSWORD=123456";
String sql = "select * from links where link_id = 1";
MySqlConnection conn = new MySqlConnection(conn);
MySqlCommand command = new MySqlCommand(sql);
conn.Open();
try{
cmmand.ExecuteNonQuery();
}
catch(Exception ex)
{
rs = true;
}
Console.WriteLine(rs==true ? "Execute success":"Execute failed");
Console.ReadLine();
Hope this help
No comments:
Post a Comment