0

Hi

I've written this code (that works) to inserts registration details into an Access 2010 DB from an aspx registration page.

How do I check for duplicates Email before inserting a new record into the DB

Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\InetPub\WWWRoot\BushHouseGibraltar\Bush.accdb;Persist Security Info=False;"

 Dim MySQL As String = "INSERT INTO Reg " & _
            "(Email,Title,FirstName,LastName,Address1,Address2,City,Phone) VALUES " & _
            "('" & EmailAddress.Text & "','" & DropDownList1.Text & "','" _
            & FirstName.Text & "','" & LastName.Text & "','" _
            & Address1.Text & "','" & Address2.Text & "','" _
            & City.Text & "','" & Phone.Text & "')"

            Dim MyConn As New Data.OleDb.OleDbConnection(strConn)
            Dim cmd As New Data.OleDb.OleDbCommand(MySQL, MyConn)
            MyConn.Open()
            cmd.ExecuteNonQuery()


        MyConn.Close()

Thanks
ViRiPuFF

Edited by mike_2000_17: Fixed formatting

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by ViRiPuFF
0

Make that column unique in database, when you try to insert duplicate email it will give you error. So handle that error and give message to user.

0

first generate Select query for getting rows of checking Exist Email from your databse
like 'Select EmailId from table where EmailID='EmailAddress.Text'

and if exist then show alert else insert your data

0

Thanks

I try this out this evening at the momemnt I am on a 15 min break from work. Thanks again.

ViRiPuFF

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.