Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- using System.Configuration;
- public partial class Register : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (IsPostBack)
- {
- SqlConnection studConn = new SqlConnection(ConfigurationManager.ConnectionStrings["StudConnectionString"].ConnectionString);
- studConn.Open();
- string checkuser = "select count(*) from StudTable where-'" + TextBoxName.Text + "'";
- SqlCommand studCom = new SqlCommand(checkuser, studConn);
- int temp = Convert.ToInt32 (studCom.ExecuteScalar().ToString());
- studConn.Close();
- if (temp == 1)
- {
- Response.Write("User already exists");
- }
- }
- }
- protected void Button1_Click(object sender, System.EventArgs e)
- {
- try
- {
- Guid studGUID = Guid.NewGuid();
- SqlConnection studConn = new SqlConnection(ConfigurationManager.ConnectionStrings["StudConnectionString"].ConnectionString);
- studConn.Open();
- string insertQuery = "insert into StudTable (ID,Name,Email,Age,Continent,School,Password) values (@ID,@name,@email,@age,@cont,@school,@pass)";
- SqlCommand studCom = new SqlCommand(insertQuery, studConn);
- studCom.Parameters.AddWithValue("@ID", studGUID.ToString());
- studCom.Parameters.AddWithValue("@name", TextBoxName.Text);
- studCom.Parameters.AddWithValue("@email", TextBoxEmail.Text);
- studCom.Parameters.AddWithValue("@age", TextBoxAge.Text);
- studCom.Parameters.AddWithValue("@cont", DropDownCont.SelectedItem.ToString());
- studCom.Parameters.AddWithValue("@school", TextBoxSchool.Text);
- studCom.Parameters.AddWithValue("@pass", TextBoxPass.Text);
- studCom.ExecuteNonQuery();
- Response.Redirect("Backend.aspx");
- Response.Write("Your Registration is Sucessful");
- studConn.Close();
- }
- catch (Exception ex)
- {
- Response.Write("Error:" +ex.ToString());
- }
- }
- }
- string checkuser = "select count(*) from StudTable where Name = @Name";
- SqlCommand studCom = new SqlCommand(checkuser, studConn);
- studCom.Parameters.AddWithValue("@Name", TextBoxName.Text);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement