Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vb.net

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
like image 870
shaik izaz Avatar asked Mar 16 '23 06:03

shaik izaz


1 Answers

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 & "'"
like image 87
RamNow Avatar answered May 03 '23 05:05

RamNow