Solved

How to stop an if statement

Posted on 2007-03-29
6
192 Views
Last Modified: 2010-04-23
Hi experts,

i have these two if statements. if a the updateUser.text = "Add User" And LicenseDB.AddUser(userProfile) then step
one should run
=============================================one==========
 If btnUpdateUser.Text = "Add User" And LicenseDB.AddUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been added."
        Else
            lblmsg.Text = "That user details  already exists."
        End If


else two should run
==========================two============================
        If btnUpdateUser.Text = "Update User" And LicenseDB.UpdateUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been updated."
        Else
            lblmsg.Text = "That user details  already exists."

        End If
        Me.SetControlState(ControlState.NoSelection)

        LoadData()

the proble is that when i add a user it displays
   lblmsg.Text = "That user details  already exists."  ============from step two.

How can I stop it from running into step two

==========full code=========
Private Sub btnUpdateUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateUser.Click
        'Initialing the controls
        Dim userProfile As New UserProfile
        userProfile.userProfileID = txtUserID.Text
        userProfile.userLoginID = txtUserID.Text
        userProfile.state = ddlEmp.SelectedItem.Value
        userProfile.firstName = txtFirstName.Text
        userProfile.lastName = txtLastName.Text
        userProfile.address1 = txtAddress1.Text
        userProfile.address2 = txtAddress2.Text
        userProfile.city = txtCity.Text
        userProfile.state = ddlState.SelectedValue
        userProfile.email = txtEmail.Text
        userProfile.phone = txtphone.Text
        userProfile.zip = txtZip.Text
        userProfile.employeeflag = ddlEmp.SelectedValue
        userProfile.username = txtUserName.Text
        userProfile.password = txtCreatePass.Text
        'update users
        If btnUpdateUser.Text = "Add User" And LicenseDB.AddUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been added."
        Else
            lblmsg.Text = "That user details  already exists."
        End If


        If btnUpdateUser.Text = "Update User" And LicenseDB.UpdateUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been updated."
        Else
            lblmsg.Text = "That user details  already exists."

        End If
        Me.SetControlState(ControlState.NoSelection)

        LoadData()
    End Sub
#End Region


thanks
0
Comment
Question by:SirReadAlot
  • 4
  • 2
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18815586
       If btnUpdateUser.Text = "Add User" then
          if LicenseDB.AddUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been added."
          Else
             lblmsg.Text = "That user details  already exists."  
          end if
        End If


        If btnUpdateUser.Text = "Update User"  then
          if LicenseDB.UpdateUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been updated."
          Else
            lblmsg.Text = "That user details  already exists."
          end if
        End If
0
 

Author Comment

by:SirReadAlot
ID: 18815597
i will try this
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18815602
I would rewrite like this:

select case btnUpdateUser.Text
  case "Add User"
     if LicenseDB.AddUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been added."
          Else
             lblmsg.Text = "That user details  already exists."  
          end if
  case "Update User"
      if LicenseDB.UpdateUser(userProfile) Then
            Me.ClearFields()
            lblmsg.Text = "The user has been updated."
          Else
            lblmsg.Text = "That user details  already exists."
          end if
End Select
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:SirReadAlot
ID: 18815614
will try this as well
0
 

Author Comment

by:SirReadAlot
ID: 18815969
THANKS
0
 

Author Comment

by:SirReadAlot
ID: 18815985
I USED THIS

#Region " btnUpdateUser Subroutine "
    Private Sub btnUpdateUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateUser.Click
        'Initialing the controls
        Dim userProfile As New UserProfile
        userProfile.userProfileID = txtUserID.Text
        userProfile.userLoginID = txtUserID.Text
        userProfile.state = ddlEmp.SelectedItem.Value
        userProfile.firstName = txtFirstName.Text
        userProfile.lastName = txtLastName.Text
        userProfile.address1 = txtAddress1.Text
        userProfile.address2 = txtAddress2.Text
        userProfile.city = txtCity.Text
        userProfile.state = ddlState.SelectedValue
        userProfile.email = txtEmail.Text
        userProfile.phone = txtphone.Text
        userProfile.zip = txtZip.Text
        userProfile.employeeflag = ddlEmp.SelectedValue
        userProfile.username = txtUserName.Text
        userProfile.password = txtCreatePass.Text
        'update users
        Select Case btnUpdateUser.Text
            Case "Add User"
                If LicenseDB.AddUser(userProfile) Then
                    Me.ClearFields()
                    lblmsg.Text = "The user has been added."
                Else
                    lblmsg.Text = "That username already exists."
                End If
            Case "Update User"
                If LicenseDB.UpdateUser(userProfile) Then
                    Me.ClearFields()
                    lblmsg.Text = "The user has been updated."
                Else
                    lblmsg.Text = "That username already exists."
                End If
        End Select
        Me.SetControlState(ControlState.NoSelection)

        LoadData()
    End Sub
#End Region
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now