应该为真的 if 语句的问题出现为假

问题描述

我们最近将一个非常旧的站点迁移到了新服务器,但遇到了一个奇怪的问题。有一个简单的 if 语句在旧服务器上应该并且确实读取为 true 但它不是,也不知道为什么。声明如下。当我写出 invflag 时,它等于 1,这正是我所期望的。

'does not trigger as true so iChk remains = ""
iChk = ""
if invflag = True then
    iChk = "checked"
end if

'Works as expected
iChk = ""
if invflag = "1" then
    iChk = "checked"
end if

'works as expected
iChk = ""
if invflag = 1 then
    iChk = "checked"
end if

我知道我们可以像您看到的那样简单地解决这个问题,但是我们在整个代码中散布着这些类型的语句,如果服务器或数据库中有一些我们可以设置的东西,那将是理想的,我想我会检查一下。

>

解决方法

简单地强制转换为 public static void Main(string[] args) Exception occured: LibGit2Sharp.LibGit2SharpException: request failed with status code: 401 at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteHandle remote,IEnumerable`1 refSpecs,GitFetchOptions fetchOptions,String logMessage) at LibGit2Sharp.Commands.Fetch(Repository repository,String remote,IEnumerable`1 refspecs,FetchOptions options,String logMessage) at LibGit2Sharp.Commands.Pull(Repository repository,Signature merger,PullOptions options) 应该适用于所有情况:

CBool

或更好

If CBool(invflag) = True Then
    iChk = "checked"
End If
,

事实证明,在从 MSSQL 迁移到 Mysql 的过程中,它将 Bit 字段转换为 TinyInt。一旦我们将字段改回 Bit,if 语句就会像以前一样工作。