【发布时间】:2014-07-10 21:26:37
【问题描述】:
If (UsersTableAdapter.FillByUsername(Me.DatabaseDataSet1.users, username) <> 0) Then
type = DatabaseDataSet1.users.First.UserType
MsgBox(type)
If type = "Staff" Then
MsgBox("You are staff")
ElseIf type = "Student" Then
MsgBox("You are student")
Else
MsgBox("Something else")
End If
End If
我的代码首先从数据库中获取用户的UserType。然后它将type 的值与Staff 和Student 进行比较。我添加了一个消息框来输出type,并确认type 已从数据库中正确提取。
为什么if 在比较中没有返回true?
我也尝试过使用.equals() 和.toString() 函数,但仍然没有成功。
【问题讨论】:
-
同样的情况? "Staff" "staff" 还检查类型变量末尾是否有隐藏空格(对于 "Staff",MsgBox(type.Length) 应该为 5)
-
是时候开始使用枚举而不是字符串了。
标签: string visual-studio visual-studio-2013 comparison basic