标签:style blog io ar color os 使用 sp 数据
using MySql.Data.MySqlClient; using System; namespace ConsoleTest { class Program { static string connectionString = "server=localhost;user id=lqs2011;password=******;database=toucai"; static void Main(string[] args) { MySqlConnection connection = new MySqlConnection(connectionString); connection.Open(); if (connection.State == System.Data.ConnectionState.Open) Console.WriteLine("connection opened!"); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = "SELECT empID, empNickName FROM employee"; cmd.CommandType = System.Data.CommandType.Text; MySqlDataReader dataReader = cmd.ExecuteReader(); if (dataReader.HasRows) Console.WriteLine("get data successfully!"); while (dataReader.Read()) Console.WriteLine(dataReader.GetString(0)+ ‘\t‘ + dataReader.GetString(1)); } } }
输出结果:
connection opened!
get data successfully!
MY001 兰瓜
MY002 小倩
MY003 松松
请按任意键继续. . .
标签:style blog io ar color os 使用 sp 数据
原文地址:http://www.cnblogs.com/lqs2011/p/4107862.html