我想通过将列“ ColName”中的字符串替换为以下内容来更新访问数据库表“ TableName”:
Dim Sql As String = "UPDATE [" & TableName & "] SET [" & ColName & "] = REPLACE([" & ColName & "], '" & OldPart & "', '" & NewPart & "')"
Dim Cmd As new OleDbCommand
Cmd.Connection = My data bsae connection string
Cmd.CommandType = CommandType.Text
Cmd.CommandText = Sql
Cmd.ExecuteNonQuery()
我收到以下错误:
条件表达式中的数据类型不匹配。
我的代码有什么问题?
答案 0 :(得分:2)
您可能有一些空字段,请尝试以下操作:
Dim Sql As String = "UPDATE [" & TableName & "] SET [" & ColName & "] = REPLACE([" & ColName & "], '" & OldPart & "', '" & NewPart & "') WHERE [" & ColName & "] Is Not Null"