1

我有一个要由用户填写的表格,它有一个复选框来确定用户帐户是否处于活动状态,如果选中该复选框,我想知道它在数据库中是否有用户名和密码,如果不是 msgbox应该出现。我有一个正在研究我需要确定 if 语句......它是否正确,如果不是请解释。

      Protected Sub ibtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ibtnSave.Click
    objBU_Accounts_Contacts = New BU_Accounts_Contacts
    Dim err As Integer
    With objBU_Accounts_Contacts
        .FK_AccountId = AccountID
        .ContactEmail = txtConEmail.Text
        .ContactFax = txtConFax.Text
        .ContactMobile = txtConMobile.Text
        .ContactName = txtContactName.Text
        .ContactTitle = txtContactTitle.Text
        .ContactTelephone = txtConTel.Text
        .PharmaLicNo = ""
        .PharmaExpDate = ""
        .HasCredintials = False

        If chkActive.Checked = True Then
            .IsActive = True
        Else
            .IsActive = False
        End If
        .IsApproved = True
        .IsMainContact = False
        .Password = ""
        .Remarks = txtConRemarks.Text
        .UserName = ""
        .SecurityAnswer = ""
        .SecurityQuestion = ""

        If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName) And (objBU_Accounts_Contacts.Password) IsNot Nothing) Then
            err = .Add()
        Else
            MsgBox("E-submission Account Not Created, Plaese Create One First")
        End If

        If ContactID = 0 Then
            err = .Add()
        Else
            .ContactId = ContactID
            err = .Update()
        End If
    End With
    If err = 0 Then
        If SessionVariables.CultureInfo = "en-US" Then
            CtlCommon.ShowMessage(Me.Page, "Saved Successfully")
        Else
            CtlCommon.ShowMessage(Me.Page, "تم الحفظ بنجاح")
        End If
    Else
        If SessionVariables.CultureInfo = "en-US" Then
            CtlCommon.ShowMessage(Me.Page, "Error while saving")
        Else
            CtlCommon.ShowMessage(Me.Page, "خطأ أثناء الحفظ")
        End If
    End If
    FillGrid()
    ClearAll()
End Sub
4

1 回答 1

5

如果你的意思是,这个 if 语句......

If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName) And (objBU_Accounts_Contacts.Password) IsNot Nothing) Then

你应该改为

If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName IsNot Nothing) And (objBU_Accounts_Contacts.Password IsNot Nothing)) Then

我想说,你可以一一比较。

于 2012-12-24T11:36:54.757 回答