SqlDataReader迴圈內 進行資料庫動作
我相信這是可以克服的 = =
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
11/22 19:40, 1F
→
11/22 22:20, , 2F
11/22 22:20, 2F
→
11/23 01:43, , 3F
11/23 01:43, 3F
→
11/23 14:00, , 4F
11/23 14:00, 4F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章
10
25