vb.net “错误:运算符 '&' 没有为类型 'String' 和 'System.Windows.Forms.TextBox' 定义。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29941382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Error: Operator '&' is not defined for types 'String' and 'System.Windows.Forms.TextBox'."
提问by shaik izaz
Im getting an error as in both SAVEand UPDATEbutton in .CommandText
我在.CommandText 中的SAVE和UPDATE按钮中都收到错误
"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.
我不知道 SAVE 和 UPDATE 按钮中的错误是什么。
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
回答by RamNow
The answer is probably very easy:
答案可能很简单:
You didn't call the Text-Property every time you used a TextBox value.
您没有在Text每次使用 TextBox 值时调用-Property。
Look at the TxtCityvariable:
查看TxtCity变量:
"'and CITY = '" & TxtCity & "'"
should be
应该
"'and CITY = '" & TxtCity.Text & "'"

