Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I create the insert trigger in the registration table.

Registration table:

UserID | UserName | Password | Confirm | Email

Insert trigger:

SQL
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.
Posted
Comments
Sergey Alexandrovich Kryukov 25-Oct-15 20:23pm    
No, I don't think this is the error message.
—SA
DamithSL 25-Oct-15 23:12pm    
debug and check which lines of code executed when you try to insert already existing record. this error not came from if condition code block, may be else condition code block
Member 12045962 26-Oct-15 3:23am    
I also dont know... Yeah, I debugged my code. It was giving me error on line SqlDataReader then I put Block... After it , shows me msg box 'System.Winform.ErrorProv'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900