C# MySQL second DataReader in DataReader while loop

后端 未结 3 540
南旧
南旧 2020-12-18 12:06

As you might have guessed from the title am I trying to do this:

    #region check new nations
    private void checknewnations()
    {
        addtolog(\"se         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 13:00

    DataReader holds on to connection until it iterates through all its records. Try this

    using(reader)
    {
       System.Data.DataTable dt = new System.Data.DataTable();
       dt.Load(reader);
    
       foreach(DataRow row in dt.Rows)
       {
            addtolog("mysql",row["nations_name"].ToString());
    
            int nation_ID = int.Parse(row["nations_ID"].ToString());
            string nation_name = row["nations_name"].ToString();
            string user_ID = row["nations_user"].ToString();
    
    
            addnation(nation_ID, nation_name, user_ID);
       }
    }
    

    This way the two reader are not sharing the same connection

提交回复
热议问题