Click here to Skip to main content
15,912,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello i'am a student and i have a project website that have a registration form and sql database i want to limit the registration maximum is 50 then when the limit is reach user cannot allowed to register something like that.



C#


protected void Button1_Click(object sender, EventArgs e)
   {



       if (temp == 0)
       {
           try
           {
               SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["registrationConnectionString"].ConnectionString);
               conn.Open();
               string insertquerry = "insert into userdata(VerificationNumber,FirstName,LastName,Gender,Birthday,CivilStatus,EmailID,MobileNumber,Address,DateRegistered,ExamSchedule) values (@VERIFY ,@FN ,@LN ,@GENDER ,@MONTH ,@CS ,@EMAIL ,@CP ,@ADRESS ,@DATE ,@SCHED)";
               SqlCommand com = new SqlCommand(insertquerry, conn);
               com.Parameters.AddWithValue("@VERIFY", TextBoxVERIFY.Text);
               com.Parameters.AddWithValue("@FN", TextBoxFN.Text);
               com.Parameters.AddWithValue("@LN", TextBoxLN.Text);
               com.Parameters.AddWithValue("@GENDER",              DropDownListGENDER.SelectedItem.ToString());
               com.Parameters.AddWithValue("@MONTH", TextBoxBD.Text);
               com.Parameters.AddWithValue("@CS", DropDownListCS.SelectedItem.ToString());
               com.Parameters.AddWithValue("@EMAIL", TextBoxEMAIL.Text);
               com.Parameters.AddWithValue("@CP", TextBoxCP.Text);
               com.Parameters.AddWithValue("@ADRESS", TextBoxADRESS.Text);
               com.Parameters.AddWithValue("@DATE", LabelTIME.Text);
              LabelTIME.Text = DateTime.Now.ToString();
              com.Parameters.AddWithValue("@SCHED", DropDownListSCHED.SelectedItem.ToString());


               com.ExecuteNonQuery();

               StreamWriter thepath = new StreamWriter("C:\\inetpub\\ftproot\\reg.txt", true);

               using (StreamWriter writer = (thepath))
               {
                   writer.WriteLine("[" + TextBoxFN.Text + "]" + "[" + TextBoxLN.Text + "]" + "[" + TextBoxVERIFY.Text + "]" + "[" + DropDownListGENDER.SelectedItem.ToString() + "]" + "[" + TextBoxBD.Text + "]" + "[" + DropDownListCS.SelectedItem.ToString() + "]" + "[" + TextBoxEMAIL.Text + "]" + "[" + TextBoxCP.Text + "]" + "[" + TextBoxADRESS.Text + "]" + "[" + LabelTIME.Text + "]" + "[" + DropDownListSCHED.SelectedItem.ToString() + "]");


               }


               {
                   Session["VerificationNumber"] = TextBoxVERIFY.Text;
               }

               Response.Redirect("registersuccess.aspx");

               conn.Close();
           }
           catch (Exception ex)
           {
               Response.Write("Error:" + ex.ToString());
           }
       }

   }
Posted
Updated 29-Jan-15 1:32am
v7
Comments
Sinisa Hajnal 28-Jan-15 4:06am    
You mean you'll show the message when you get 50 registered users? What is the problem?
Member 11407981 28-Jan-15 4:35am    
sorry for that i mean when my sql database reach 50 registered members users cannot allowed to register something like that
Kornfeld Eliyahu Peter 28-Jan-15 4:17am    
It is very hard to read your question - you should format your code dump and remove all the unnecessary code...
OriginalGriff 28-Jan-15 4:39am    
If you are going to post code, then make it easy for us to read: format it with pre tags to preserve the formatting (Edit it, and use the "code" button above the textbox). And rip out the rubbish. Empty methods and handlers don't help us to read your code, they just get in the way and don;t help anybody. So only show us relevant code.

Then explain what your problem is in English, what you have tried, and where you are stuck. We aren't going to do it all for you!
Member 11407981 28-Jan-15 5:09am    
please help me for my project

1 solution

You should write c# code on .aspx.cs code behind

//First take
int i= 0;
 
Share this answer
 

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