SixString Posted January 23, 2004 Posted January 23, 2004 (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 July 5, 2006 by PlausiblyDamp Quote
Moderators Robby Posted January 23, 2004 Moderators Posted January 23, 2004 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. Quote Visit...Bassic Software
SixString Posted January 23, 2004 Author Posted January 23, 2004 Hi ;) Can you show me how the code would look like please ?? Thanks Quote
samsmithnz Posted January 23, 2004 Posted January 23, 2004 Of even better you could use a stored procedure that checks if the user exists before inserting, so that the entire insertion is in one step. Quote Thanks Sam http://www.samsmith.co.nz
Moderators Robby Posted January 24, 2004 Moderators Posted January 24, 2004 Yup, Stored Proc would be the way to go here. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.