Question If statement not working. Help!

jamesxg1

New member
Joined
Sep 26, 2010
Messages
1
Programming Experience
5-10
Hiya peeps!

I have a problem. I have two IF statments but neither are working.

Here is the code I have used.

Code:

VB.NET:
    Private Sub ViewUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try

            Dim connection As New MySqlConnection("server=" & My.Settings.MysqlHost & ";user id=" & My.Settings.MysqlUsername & "; password=" & My.Settings.MysqlPassword & "; port=3306; database=" & My.Settings.MysqlDatabase & "; pooling=false")
            connection.Open()

            Dim usersql As New MySqlCommand("SELECT * FROM `accounts` WHERE `id` = '" & My.Settings.VUID & "' LIMIT 1", connection)
            usersql.ExecuteNonQuery()

            Dim userreader = usersql.ExecuteReader()

            While (userreader.Read())
                Dim name As String = userreader.GetString(1) & " " & userreader.GetString(2)
                Dim accounttype = ""
                Dim activity = userreader.GetString(8)

                accname.Text = StrConv(name, VbStrConv.ProperCase)
                accid.Text = userreader.GetString(0)
                accemail.Text = userreader.GetString(3)
                accusername.Text = userreader.GetString(4)

                If userreader.GetString(9).Equals(1) Then
                    accounttype = "Tenant"
                    setpaid.Hide()
                    setunpaid.Hide()
                ElseIf userreader.GetString(9).Equals(2) Then
                    accounttype = "Landlord"
                End If

                If activity.Equals(1) Then
                    accactive.Text = "Suspended"
                    suspenduser.Hide()
                Else
                    accactive.Text = "Active"
                    unsuspend.Hide()
                End If

                acctype.Text = accounttype
                usersql.Dispose()
            End While
        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        End Try
    End Sub



That is the whole code snippet. Everything is working. But this;

Code:

VB.NET:
                If userreader.GetString(9).Equals(1) Then
                    accounttype = "Tenant"
                    setpaid.Hide()
                    setunpaid.Hide()
                ElseIf userreader.GetString(9).Equals(2) Then
                    accounttype = "Landlord"
                End If

                If activity.Equals(1) Then
                    accactive.Text = "Suspended"
                    suspenduser.Hide()
                Else
                    accactive.Text = "Active"
                    unsuspend.Hide()
                End If



If anyone has any ideas please help!

Many thanks,

James.
 
Check the result of this expression:
VB.NET:
Dim result = "1".Equals(1)
It would also be more natural to use the = comparison operator, and if you have Option Strict turned on (which is a good idea) you will actually get a compiler error forcing you to take a stand at which data type you actually want to handle, and which value you want to convert to be able to compare values of equal types.
 
Back
Top