如何将数据集的行和列与datagridview的行和列进行比较?

时间:2017-07-20 11:41:43

标签: vb.net

我在做vb.net开发。首先,我有10(行)* 7(列)。我试图将它与数据集的行和列与datagridview的行进行比较。并尝试触发更新记录的更新查询。我完成了更新查询。现在,9的位置没有行,它将正常,当它将到达行的10号位置时,它将抛出一个跟随错误。点击此图片说明,您将收到错误消息。

[错误] [1]

Try 
   Dim rowindex As Integer = 2 
   For Each row As DataGridViewRow In DataGridViewl.Rows For index = 0 To row.Cells.Count - 1 
     If row.Cells(index).Value.ToString <> 
       DS.Tables("Login").Rows(rowindex - 1)(index).ToString Then 
       Dim query As String = "update Login set Emp_Name='" + 
       row.Cells("Emp_Name").Value.ToString _ + "',Emp_Code='" + 
       row.Cells("Emp_Code").Value.ToString _ + "',Email='" + 
       row.Cells("Email").Value.ToString _ + "',Address='" + 
       row.Cells("Address").Value.ToString _ + "',MobileNo='" + 
       row.Cells("MobileNo").Value.ToString _ + "',Password='" + 
       row.Cells("Password").Value.ToString + "' where L_ID='" + 
       row.Cells("L_ID").Value.ToString + "'" 
       Sqlexe(query)
    End If 
  Next rowindex += 1 

Catch ex As Exception  
     MsgBox(ex.ToString) 
End Try 

0 个答案:

没有答案