shaik izaz
shaik izaz

Reputation: 81

"Error: Operator '&' is not defined for types 'String' and 'System.Windows.Forms.TextBox'."

Im getting an error as in both SAVE and UPDATE button in .CommandText

"Error: Operator '&' is not defined for types 'String' and 'System.Windows.Forms.TextBox'."

I don't know what is the error in both SAVE and UPDATE buttons.

Here is my code:

Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
    Try
        With cm
            .Connection = cn
            .CommandText = "insert into [edit$]values('" & TxtId.Text & "','" & TxtFamilyname.Text & "','" & TxtGivenname.Text & "','" & TxtGender.Text & "','" & TxtDob.Text & "','" & TxtExamdate.Text & "','" & TxtExamtime.Text & "','" & TxtStreet.Text & "','" & TxtHouse.Text & "','" & TxtPlz.Text & "','" & TxtCity & "' )"
            .ExecuteNonQueryAsync()
        End With
        FillDataGridView("select * from [edit$]")
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
        Return
    End Try
    MsgBox("succefully Saved!", MsgBoxStyle.Information, Text)
End Sub

Private Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles Btnupdate.Click
    Try
        With cm
            .Connection = cn
            .CommandText = "Update [edit$] set [Family Name] = '" & TxtFamilyname.Text & "' where id ='" & TxtId.Text & "' and Given Name = '" & TxtGivenname.Text & "'and Gender = '" & TxtGender.Text & "'and DOB = '" & TxtDob.Text & "'and Exam Date'" & TxtExamdate.Text & "'and Exam Time = '" & TxtExamtime.Text & "'and Street Name = '" & TxtStreet.Text & "'and House Nr = '" & TxtHouse.Text & "'and PLZ = '" & TxtPlz.Text & "'and CITY = '" & TxtCity & "'"
            .ExecuteNonQuery()
        End With
        FillDataGridView("select * from [edit$]")
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Information, Text)
        Return
    End Try
    MsgBox("Succesfully updated!", MsgBoxStyle.Information, Text)
End Sub

Upvotes: 4

Views: 22372

Answers (1)

RamNow
RamNow

Reputation: 486

The answer is probably very easy:

You didn't call the Text-Property every time you used a TextBox value.

Look at the TxtCity variable:

"'and CITY = '" & TxtCity & "'"

should be

"'and CITY = '" & TxtCity.Text & "'"

Upvotes: 7

Related Questions