vb 2008:标准表达式中的数据类型不匹配 [英] vb 2008: Datatype mismatch in criteria expression

查看:129
本文介绍了vb 2008:标准表达式中的数据类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在更新记录时构建更新代码时遇到此错误。而且我不知道该怎么做。我知道这个。请帮助:)



这里是我的代码:





Private Sub btnSave_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理btnSave.Click

Dim str As String

str =UPDATE EmployeeTable set [ EmployeeName] =''&txtEmpName.Text&'',[Address] =''&txtAddress.Text&'',[Phone] =''&txtPhone.Text&'',[HiredDate] =''&txtHiredDate.Text&'',[JobClassification] =''&txtJobClassification.Text&'',[DateAdded] =''&txtDateAdded.Text&''WHERE [EmployeeID] =' '&txtEmpID.Text&''

Dim cmd As OleDbCommand = New OleDbCommand(str,myConnection)

尝试

cmd。 ExecuteNonQuery()

Catch ex As Exception

MsgBox(ex.Message)

结束尝试

End Sub

解决方案

调试你的程序。

将你在 str 变量中生成的查询复制到Sql Server Management Studio并运行它。



检查你得到了什么错误并相应地更正了声明。



作为一个注释,传递查询绝不是一个好主意数据直接写入字符串。

使用命令参数而不是 [ ^ ]。


hi folks,
i get this error when im building my update code in updating my record. and i dont know what to do. im knew to this. pls help :)

here''s my code:


Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim str As String
str = "UPDATE EmployeeTable set [EmployeeName] = ''" & txtEmpName.Text & "'' , [Address] = ''" & txtAddress.Text & "'', [Phone] = ''" & txtPhone.Text & "'', [HiredDate] = ''" & txtHiredDate.Text & "'', [JobClassification] = ''" & txtJobClassification.Text & "'',[DateAdded] = ''" & txtDateAdded.Text & "'' WHERE [EmployeeID] = ''" & txtEmpID.Text & "''"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

解决方案

Debug your program.
Copy the query you generate in str variable into Sql Server Management Studio and run it.

Check what error you get and correct the statement accordingly.

As a note, it is never a good idea to pass query data directly into a string.
Use command parameters instead[^].


这篇关于vb 2008:标准表达式中的数据类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆