SqlDataReader迴圈內 進行資料庫動作

看板C_Sharp (C#)作者 (加油加油^^)時間13年前 (2011/11/22 17:35), 編輯推噓0(004)
留言4則, 4人參與, 最新討論串1/1
我相信這是可以克服的 = = SqlConnection conn = new SqlConnection("xxxxxx"); //開啟連線 是成功的 conn.Open(); //打開 SqlDataReader reader = new SqlCommand("SELECT * FROM apply",conn) .ExecuteReader(); while (reader.Read()) { Response.Write(reader.GetInt32(0) + "|<br>"); Response.Write(reader.GetString(1) + "|<br>"); Response.Write("<hr>"); new SqlCommand("INSERT INTO [bak].[dbo].[getinto]( [name], [loc], [code], [times], [timee], [mark]) VALUES ( 'ab','ab','ab','xx','xx','')", conn).ExecuteNonQuery(); } 感覺很單純的東西 他回報給我 "已經開啟一個與這個 Command 相關的 DataReader,必須先將它關閉。" 這需求應該很常見吧? 就是在跑資料庫的過程中還要異動資料庫。 -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.218.112.35

11/22 19:40, , 1F
用 MARS 或是兩條連線做。
11/22 19:40, 1F

11/22 22:20, , 2F
Reader的確不行
11/22 22:20, 2F

11/23 01:43, , 3F
Reader不行 好像要另外設定?
11/23 01:43, 3F

11/23 14:00, , 4F
目前查 是不行的 解決方法是 建立VIEW一次做完
11/23 14:00, 4F
文章代碼(AID): #1EospiC6 (C_Sharp)
文章代碼(AID): #1EospiC6 (C_Sharp)