Can I reset and loop again through MySqlDataReader?

喜你入骨 提交于 2019-12-06 16:50:06

You can use below :

using (MySqlConnection connMySql = new MySqlConnection(global.g_connString))
            {
               MySqlCommand cmd = connMySql.CreateCommand();
                cmd.CommandText = "selece * from <table>"; 
                connMySql.Open();
                using (MySqlDataReader dr = cmd.ExecuteReader())
                {
                        DataTable dt1 = new DataTable();
                        dt1.Load(dr);
                        // You can use this dt1 anywhere in the code
                 }

// parsing datatable

 DataTable dt = new DataTable();
    if (dt.Rows.Count > 0)
    {
        for (int count = 0; count < dt.Rows.Count; count++)
        {
            string str= dt.Rows[count]["[ColumnName]"].ToString();  
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!