0

如何检查电子邮件是否在数据库中但不包括登录用户的电子邮件?我在注册以检查数据库中的电子邮件时在我的项目中使用此代码,它工作正常......但我想提供更新注册客户的电子邮件的选项,从而排除计算他自己的电子邮件。当访问我的个人资料页面(客户可以更新他的数据的页面)时,我正在提取所有信息并将其写入文本框中,因此即使他只更新了他的姓名,其余所有信息也会被相同的数据覆盖。这是适用于所有电子邮件的代码:

 Function GetEmail() As Boolean
    Dim EmailOk As Boolean
    Dim CustomerId As Integer = 0

    Try
        If IsNothing(Session("UserName")) Or Session("UserName").ToString() = "" Then
            Response.Redirect("../Login.aspx")
        Else
            CustomerId = Convert.ToInt32(Session("CustomerID"))
        End If
    Catch ex As Exception
        Response.Redirect("../Login.aspx")
    End Try


    'declares an instance of the database object allowing us to get the data from the table

    Dim tblCustomer As New DatabaseTable("Members.mdb", "select Email from tblCustomer", "#PN", "#PW")
    'declaring variables for loop
    Dim EmailNumber As Integer = 0
    Dim EmailCount As Integer
    Dim Email As String = txtEmail.Text
    Dim Counter As Integer
    'get the number of the emails
    EmailCount = tblCustomer.Count
    'loop thrue each item
    For Counter = 0 To EmailCount - 1
        'adds number to counter, if found message that subscribed
        If Email = tblCustomer.RecordNumber(Counter).Item("EMail") Then
            EmailNumber = EmailNumber + 1
            EmailOk = False
            'if did not find email will message that not subscribed
        ElseIf EmailNumber = 0 Then
            EmailOk = True

        End If
    Next

    Return EmailOk
End Function

>

这是我尝试过的更改,我认为它会起作用,但没有......

Dim tblCustomer As New DatabaseTable("Members.mdb", "select Email from tblCustomer where CustomerID <>" + CustomerId.ToString() + " ", "#PN", "#PW")

CustomerID.ToString() 是从会话中写入的登录客户 ID,因此是当前客户 ID 任何想法?

4

1 回答 1

0

好的,我确实解决了这个问题!我花了一些时间,它不是太专业,但它确实有效!我在登录时将用户的电子邮件存储在会话中。我仍然使用相同的代码来检查电子邮件是否在数据库中,但我只运行检查客户是否更改了文本框中的电子邮件。所以首先我检查文本框中的电子邮件是否 = 会话电子邮件,如果不是一切都很好,因为电子邮件保持不变,并且在注册时验证它是正确的。而且它与我运行验证代码不同。它看起来很乱,所以如果有人仍然对如何做有更好的想法,请告诉我。如您所见,我必须编写相同部分的代码两次,因为有两种可能验证是可以的,但我只能在客户更改电子邮件文本框时运行 GetEmail()。

lbltester.Text = Session("UserEmail")
If txtEmail.Text = lbltester.Text Then
Dim myCustomers As New clsCustomer
clsCustomer.Update(txtFirstName.Text.Trim(), txtLastName.Text.Trim(), txtHouseNumber.Text.Trim(), txtStreet.Text.Trim(), txtCity.Text.Trim(), txtCounty.Text.Trim(), txtCountry.Text.Trim(), TxtPostCode.Text.Trim(), txtPhone.Text.Trim(), txtEmail.Text.Trim(), CustomerId)
Dim popupScript As String = "alert('Profile Updated Sucessfully');"
ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, True)
Else
Call GetEmail()
     If EmailOk = True Then
     Dim myCustomers As New clsCustomer
     clsCustomer.Update(txtFirstName.Text.Trim(), txtLastName.Text.Trim(), txtHouseNumber.Text.Trim(), txtStreet.Text.Trim(), txtCity.Text.Trim(), txtCounty.Text.Trim(), txtCountry.Text.Trim(), TxtPostCode.Text.Trim(), txtPhone.Text.Trim(), txtEmail.Text.Trim(), CustomerId)
     Session("UserName") = txtFirstName.Text.Trim() + " " + txtLastName.Text.Trim()
      Dim popupScript As String = "alert('Profile Updated Sucessfully');"
      ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, True)

        Else

        Dim popupScript As String = "alert('Email already exist in database');"
        ClientScript.RegisterStartupScript(Page.GetType(), "script", popupScript, True)
        txtEmail.Focus()
        End If
     End If
于 2013-04-06T23:05:17.840 回答