标签:
class Program { static void Main(string[] args) { //连接数据库 using( MySqlConnection conn = new MySqlConnection("Server=localhost; Database=study; uid=root; pwd=root; Charset=utf8;") ) //创建数据库对象 using (MySqlCommand cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "SELECT * FROM t_customers"; using (MySqlDataReader read = cmd.ExecuteReader()) { while (read.Read())//读取每行数据 { //获取字段信息 int id = read.GetInt32("Id"); string name = read.GetString("Name"); string age = read.GetString("Age"); Console.WriteLine(id + name + age); } } } Console.ReadKey(); } }
标签:
原文地址:http://www.cnblogs.com/phpweige/p/4783095.html