| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
wen5
9年前发布

C#操作MySql数据库范例代码

首先到网上下载MySql.Data.MySqlClient.dll,然后添加引用到项目

using MySql.Data.MySqlClient;               string connectString = @"server=localhost;userid=root;password=xxx;database=sharejs";   /*由于我的数据库在本地就用localhost了,可以替换成IP地址*/                 MySqlConnection conn = new MySqlConnection(connectString);                 conn.Open ();                 MySqlCommand cmd = conn.CreateCommand();                 cmd.CommandText = "select * from info";                 cmd.CommandType = CommandType.Text;                 using (MySqlDataReader reader = cmd.ExecuteReader())                 {                     while (reader.Read())                       Console.WriteLine(reader[0].ToString());                 }