我的sql server中有数据库。在我的网页上,我创建了一个表格(gridview)。而是创建一个表单(txtbox),我希望用户在表格中输入他们的数据。
这是我的gridview的VB代码:
Private Sub LoadGridStaff()
Dim q As String
For r = 0 To gvTable.Rows.Count - 1
q = "INSERT INTO staff_OT (Staff_no, Staff_name, OverTime, PayCode)" & _
"values('" & gvTable.Rows.Cells(0).Value & " ', ' " & gvTable.Rows.Cells(1).Value & "','" & gvTrans.Rows.Cells(2).Value & " ', '" & gvTrans.Rows.Cells(3).Value & " ')"
Next
End Sub
错误是:
Cells'不是'System.Web.Ui.WebControls.GridviewRowCollection'的成员
答案 0 :(得分:1)
您需要使用循环的迭代变量指示RowCollection
的索引。
Private Sub LoadGridStaff()
Dim q As String
For r = 0 To gvTable.Rows.Count - 1
q = "INSERT INTO staff_OT (Staff_no, Staff_name, OverTime, PayCode)" & _
"values('" & gvTable.Rows(r).Cells(0).Value & " ', ' " & gvTable.Rows(r).Cells(1).Value & "','" & gvTrans.Rows(r).Cells(2).Value & " ', '" & gvTrans.Rows(r).Cells(3).Value & " ')"
'do db work
Next
End Sub