user3562155
user3562155

Reputation: 51

Edit/Update datagridview VB form

When I try to edit and update the data in datagriview it comes up with an error message saying Operator '&' is not defined for type 'TextBox' and string "".

please help. Thanks

Here is my code

 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

Upvotes: 0

Views: 50

Answers (1)

Origin
Origin

Reputation: 2023

In the future, you should also post the line number the error is being thrown on.

The error is telling you that you're doing something like:

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

in this case, you would need to do:

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

In the code you posted, I wasn't able to find an instance of this - so perhaps its somewhere else in the code. Though, the code was hard to read so I may have missed it.

You may also be aware that this code is susceptible to SQL Injection attacks

Upvotes: 1

Related Questions