Private Sub btnCIAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnCIAdd.Click
Dim cistatus, cifn, ciln, cicontact, cieadd, cidoa, ciRD, ciRT, ciRN, ciPPD, ciMOP, ciAmount As String
Dim i, cicid As Integer
For i = 0 To Me.DataGridView1.Rows.Count - 1
cicid = DataGridView1.Rows(i).Cells(0).Value
cistatus = Me.DataGridView1.Rows(i).Cells(1).Value
cifn = Me.DataGridView1.Rows(i).Cells(2).Value
ciln = Me.DataGridView1.Rows(i).Cells(3).Value
cicontact = Me.DataGridView1.Rows(i).Cells(4).Value
cieadd = Me.DataGridView1.Rows(i).Cells(5).Value
Next
cidoa = DateTimePicker2.Text
ciRD = txtCIRD.Text
ciRT = comboCIRT.Text
ciRN = comboCIRN.Text
ciPPD = txtCIPD.Text
ciMOP = comboCIMD.Text
ciAmount = txtCIAmount.Text
cmd = "INSERT INTO checkin_info VALUES ('" & cicid & "','" & cistatus & "','" & cifn & "','" & ciln & "','" & cicontact & "','" & cieadd & "',','" & cidoa & "','" & ciRD & "','" & ciRT & "','" & ciRN & "','" & ciPPD & "','" & ciMOP & "')"
rs.CommandText = cmd
res = rs.ExecuteReader()
MessageBox.Show("Entry added!")
End Sub
這是我的整個私人小組,我得到的錯誤像「變量'cicontact'之前使用它已被分配一個值。在運行時「與cistatus,cifn,ciln,cicontact和cieadd一樣 我沒有得到這個..我初始化是一個錯誤,我該如何解決這個問題?使用變量之前,它已被分配一個值
您有SQL注入漏洞。 – SLaks
你的「For循環」是多餘的。所有你最終得到的是來自datagrid最後一行的值,所以你可以直接設置'i = Me.DataGridView1.Rows.Count - 1'並執行一次。 – DeanOC
它減少了它的錯誤,剩下的一個語法錯誤到了計數 –