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