I create the insert trigger in the registration table.
Registration table:
UserID | UserName | Password | Confirm | Email
Insert trigger:
ALTER TRIGGER [dbo].[LimitTtblReg]
on [dbo].[tblRegF]
after insert
as
declare @tableCount int
select @tableCount = Count(*)
from tblRegF
if @tableCount > 1
begin
rollback
end
C# code on Registration button:
if (this.ValidateChildren())
{
string c = ConfigurationManager.ConnectionStrings["Constr"].ConnectionString;
SqlConnection con = new SqlConnection(c);
try
{
con.Open();
SqlCommand cmd = new SqlCommand("RegistrationForm", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", txtRegUserN.Text);
cmd.Parameters.AddWithValue("@Password", txtRegPass.Text);
cmd.Parameters.AddWithValue("@Confirm", txtRegPassConfirm.Text);
cmd.Parameters.AddWithValue("@Email", txtRegEmail.Text);
SqlDataReader dr = cmd.ExecuteReader();
MessageBox.Show("Data Inserted Succesfully");
con.Close();
clear();
this.Close();
}
catch (Exception)
{
MessageBox.Show("you already have been registered);
}
else
{
var listOfErrors = this.errorProv.ContainerControl.Controls
.Cast<Control>()
.Select(c => this.errorProv.GetError(c))
.Where(s => !string.IsNullOrEmpty(s))
.ToList();
MessageBox.Show("please correct validation errors:\n - " +
string.Join("\n - ", listOfErrors.ToArray()),
"Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
I've set the validating event on text box and auto validate on form...
When I try to enter the information second time it shows me message box .
' System.Winform.ErrorProv'
I want to show the message
'You have already been registered'.
Please tell me how to resolve this problem.