单个ID的多个电子邮件,没有重复

时间:2016-06-21 05:16:52

标签: asp.net vb.net

  

我有一个表格寄存器,这里有2列电子邮件和id

     

在这个id中可以有多个电子邮件,但它不能重复如何   解决它

     

请帮助我是asp.net的新手

>  Public Shared Function checkvendemail(ByVal p_vendid As String, ByVal
> p_email As String) As Boolean
>             Dim CP As String
>             Using db As New SqlConnection(My.Settings.WSMplannet)
>                 db.Open()
>                 Using cmd As New SqlCommand("SELECT 1 FROM Registration where email='" + p_email + "'", db)
>                     CP = cmd.ExecuteScalar()
>                     If String.IsNullOrEmpty(CP) Then CP = "N"
>                 End Using
>                 db.Close()
>             End Using
>             Return (CP.ToUpper = "Y")
>         End Function



 If Not (PRC.DTO.PRCContractor.Queries.checkvendemail(txtVendorID.Text, txtEmailAddress.Text)) Then
            litMessage.Text = "<a style=""font-weight: normal; color: red"">Email aready Registered .</a>"
            Exit Sub
        End If

2 个答案:

答案 0 :(得分:1)

您的问题是选择...您选择1 ...也使用参数...

 SELECT 1 FROM...

尝试COUNT

 SELECT COUNT(*) FROM

然后检查你的情况。使CP为整数然后检查CP ...

例如

 If CP > 0 Then Return True Else Return False

答案 1 :(得分:1)

试试这个:

Public Shared Function checkvendemail(ByVal p_vendid As String, ByVal p_email As String) As Boolean
    Dim CP As String
        Using db As New SqlConnection(My.Settings.WSMplannet)
            db.Open()
            Using cmd As New SqlCommand("SELECT 1 FROM Registration where UPPER(email) = '" + p_email.ToUpper() + "' AND id = " + p_vendid, db)
                CP = cmd.ExecuteScalar()
                If String.IsNullOrEmpty(CP) Then CP = "N"
            End Using
            db.Close()
        End Using
    Return (CP.ToUpper = "Y")
End Function

您似乎没有使用p_vendid参数,这似乎是您的注册表的ID。