码迷,mamicode.com
首页 > Windows程序 > 详细

C#------DataTable

时间:2015-09-05 16:19:35      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

 class Program
    {
        static void Main(string[] args)
        {

            DataTable dt = new DataTable();
            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 reader = cmd.ExecuteReader())
                { 
                    //把数据加载到DataTable中
                    dt.Load(reader);
                }
            }

            //遍历数据
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                int id = (int)row["Id"];
                string name = (string)row["Name"];
                Console.WriteLine(id+name);
            }
            Console.ReadKey();
        }
    }

 

C#------DataTable

标签:

原文地址:http://www.cnblogs.com/phpweige/p/4783311.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!