[.NET] sql+迴圈的問題
Dim a, i, j As Integer
Dim temp As String
i = ListBox1.Items.Count - 1
Try
conn.Open()
For a = 0 To i
temp = ListBox1.Items(a)
MsgBox(a)
into = "INSERT INTO temp_sn (sn) VALUES ('" + temp + "')"
cmd = New System.Data.SqlClient.SqlCommand(into, conn)
Next
Catch ex As Exception
MsgBox("datebase error")
End Try
j = cmd.ExecuteNonQuery
conn.Close()
MsgBox(j)
以上是我的程式的片段,主要是要把listbox1.item裡面的值 全部都在寫到資料庫裡面去
我也用msgbox(a)去觀察執行的次數,出來的結果是相符的,但是不知道為什麼,在最後
真正有寫到資料庫裡面的資料 卻只有一筆?是語法有錯誤嗎?還是不能這樣用?
在此麻煩各位版大,給我這答案了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.116.189.146
推
08/21 16:21, , 1F
08/21 16:21, 1F
→
08/21 16:21, , 2F
08/21 16:21, 2F
→
08/21 16:22, , 3F
08/21 16:22, 3F
→
08/21 16:23, , 4F
08/21 16:23, 4F
推
08/21 16:43, , 5F
08/21 16:43, 5F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):