Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String Visual Basic字符串等于运算符不工作 If(UsersTableAdapter.FillByUsername(Me.DatabaseDataSet1.users,username)0)则 type=DatabaseDataSet1.users.First.UserType MsgBox(类型) 如果type=“Staff”,则 MsgBox(“您是员工”) ElseIf type=“学生”则 MsgBox(“您是学生”) 其他的 MsgBox(“其他东西”) 如果结束 如果结束_String_Visual Studio_Visual Studio 2013_Comparison_Basic - Fatal编程技术网

String Visual Basic字符串等于运算符不工作 If(UsersTableAdapter.FillByUsername(Me.DatabaseDataSet1.users,username)0)则 type=DatabaseDataSet1.users.First.UserType MsgBox(类型) 如果type=“Staff”,则 MsgBox(“您是员工”) ElseIf type=“学生”则 MsgBox(“您是学生”) 其他的 MsgBox(“其他东西”) 如果结束 如果结束

String Visual Basic字符串等于运算符不工作 If(UsersTableAdapter.FillByUsername(Me.DatabaseDataSet1.users,username)0)则 type=DatabaseDataSet1.users.First.UserType MsgBox(类型) 如果type=“Staff”,则 MsgBox(“您是员工”) ElseIf type=“学生”则 MsgBox(“您是学生”) 其他的 MsgBox(“其他东西”) 如果结束 如果结束,string,visual-studio,visual-studio-2013,comparison,basic,String,Visual Studio,Visual Studio 2013,Comparison,Basic,我的代码首先从数据库中获取用户的UserType。然后将类型的值与职员和学生进行比较。我在输出type中添加了一个消息框,并确认type已正确从数据库中提取 为什么if在比较中不返回true 我也尝试过使用.equals()和.toString()函数,但仍然没有成功。我支持@Steve,知道最可能的问题是什么。您可能想尝试使用ToLower()和Trim() 请注意Steve在以下代码中提到的两种情况(大小写和隐藏空格): If (UsersTableAdapter.FillByUsernam

我的代码首先从数据库中获取用户的
UserType
。然后将
类型
的值与
职员
学生
进行比较。我在输出
type
中添加了一个消息框,并确认
type
已正确从数据库中提取

为什么
if
在比较中不返回
true


我也尝试过使用
.equals()
.toString()
函数,但仍然没有成功。

我支持@Steve,知道最可能的问题是什么。您可能想尝试使用
ToLower()
Trim()

请注意Steve在以下代码中提到的两种情况(大小写和隐藏空格):

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

同样的情况?“Staff”“Staff”还检查类型变量末尾是否有隐藏空格(“Staff”的MsgBox(type.Length)应为5)。开始使用枚举而不是字符串的时间到了。谢谢,yeh,在向db写入数据时,出于某种原因,有一堆空格出现了!
    Dim Type = "staff    "

    MsgBox(Type)

    If Type.ToLower().Trim() = "Staff".ToLower() Then
        MsgBox("You are staff")
    ElseIf Type = "Student" Then
        MsgBox("You are student")
    Else
        MsgBox("Something else")
    End If