Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi ;)

 

I was wondering if anyone can help me with this issue

 

I have this lines of code that insert a new user in the database ..but i would like to check if exists already an e-mail on the database equal to the one submited ..and if it does display a message on a label to let the customer knows that the e-mail inserted already exists .

 

Thanks in advance

 

Sub doInserir(ByVal Source As Object, ByVal E As EventArgs)

       Dim nome, endereco, cep, uf, email As String

       Dim MySQL As String = "Insert into Clientes (nome, endereco , cep , uf , email ) values (@nome, @endereco ,@cep , @uf , @email)"

       Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/teste/dados/Teste.mdb")

       Dim Cmd As New OleDbCommand(MySQL, myConn)

       Cmd.Parameters.Add(New OleDbParameter("@nome", frmnome.Text))
       Cmd.Parameters.Add(New OleDbParameter("@endereco", frmendereco.Text))
       Cmd.Parameters.Add(New OleDbParameter("@cep", frmcep.Text))
       Cmd.Parameters.Add(New OleDbParameter("@uf", frmestado.Text))
       Cmd.Parameters.Add(New OleDbParameter("@email", frmemail.Text))

       myConn.Open()

       Cmd.ExecuteNonQuery()

       myConn.Close()

      End Sub

Edited by PlausiblyDamp
  • Moderators
Posted

Before your insert use the ExecuteScalar of the command object with something like this.

 

Select Count(*) from Clientes Where email = '" & frmemail.Text & "'"

 

If the return is 0 then go ahead and insert otherwise do not continue with the insert.

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...