vb.net - "Error: Operator ' & ' is not defined for types ' 字符串 ' and ' System.Windows.Forms.TextBox '."

标签 vb.net

我得到一个错误,如 保存 更新 中的按钮.CommandText

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

我不知道 SAVE 和 UPDATE 按钮的错误是什么。

这是我的代码:
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

最佳答案

答案可能很简单:

您没有调用 Text - 每次使用 TextBox 值时的属性。

TxtCity多变的:

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

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

关于vb.net - "Error: Operator ' & ' is not defined for types ' 字符串 ' and ' System.Windows.Forms.TextBox '.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29941382/

相关文章:

MySqlDataAdapter.update() 不使用 DataRelation 更新 DataRow

c# - 帮助理解 .NET 委托(delegate)、事件和事件处理程序

c# - 使用 VB.Net 在 Internet Explorer 中捕获 Javascript 警报

asp.net - ItemIndex asp :Repeater VB. NET 的内联 IF 语句

vb.net - 无需注册DLL即可调用VB.Net DLL中的函数

vb.net - 根据不同对象的状态更改 contextMenuStrip

asp.net - 隐藏/显示的 AsyncFileUpload 控件不会触发服务器端 UploadedComplete 事件

c# - 添加 Web 引用时拒绝访问路径

vb.net - .NET 无需 Microsoft.Office.Interop 即可读取 word/excel 文档

.net - 如何处理一次性元素 list ?