编辑/更新datagridview VB表单

时间:2015-01-21 11:46:27

标签: vb.net visual-studio-2010

当我尝试编辑和更新datagriview中的数据时,会出现一条错误消息,说明操作员'&'未定义类型'TextBox'和字符串“”。

请帮忙。感谢

这是我的代码

 Private Sub btnaddrecord_Click(sender As Object, e As EventArgs) Handles btnaddrecord.Click

    Dim cmd As New OleDb.OleDbCommand
    If Not cnn.State = ConnectionState.Open Then

        cnn.Open()
    End If

    cmd.Connection = cnn

    If Me.IdentificationNotest.Tag & "" = "" Then

        cmd.CommandText = "INSERT INTO vehicledefects(Codenumber, vehiclereg, datereported, defects1, repaired1, defects2, repaired2, defects3, repaired3, datefixed) " & _
        " VALUES(" & Me.IdentificationNotest.Text & ",'" & Me.vehiclereg.Text & "','" & Me.datereported.Text & "','" & Me.defects1.Text & "','" & Me.repaired1.Text & "','" & _
        Me.defects2.Text & "','" & Me.repaired2.Text & "','" & _
        Me.defects3.Text & "','" & Me.repaired3.Text & "','" & _
        Me.datefixed.Text & "')"
        cmd.ExecuteNonQuery()
    Else

        cmd.CommandText = "UPDATE vehicledefects" & _
         " SET Codenumber =" & Me.IdentificationNotest.Text & _
          ", vehiclereg ='" & Me.vehiclereg.Text & "'" & _
            ", datereported ='" & Me.datereported.Text & "'" & _
            ", defects1 ='" & Me.defects1.Text & "'" & _
            ", repaired1 ='" & Me.repaired1.Text & "'" & _
            ", defects2 ='" & Me.defects2.Text & "'" & _
            ", repaired2='" & Me.repaired2.Text & "'" & _
            ", defects3='" & Me.defects3.Text & "'" & _
            ", repaired3='" & Me.repaired3.Text & "'" & _
            ", datefixed='" & Me.datefixed.Text & "'" & _
         " WHERE Codenumber =" & Me.IdentificationNotest.Tag
        cmd.ExecuteNonQuery()
    End If

    refreshdata()

    Me.btnclear.PerformClick()

    cnn.Close()
    datefixed.Text = ""
    IdentificationNotest.Text = ""

End Sub

1 个答案:

答案 0 :(得分:1)

将来,您还应该发布错误所在的行号。

错误告诉您,您正在执行以下操作:

dim myString as String = myTextBox & " some more text"

在这种情况下,你需要这样做:

dim myString as String = myTextBox.Text & " some more text"

在您发布的代码中,我无法找到此实例 - 所以也许它在代码中的其他位置。虽然,代码难以阅读,所以我可能错过了它。

您可能也知道此代码容易受到SQL Injection attacks

的影响