Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.Configuration;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- namespace TestGrounds
- {
- public partial class NewUser : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btnRegisterUser_Click(object sender, EventArgs e)
- {
- lblError.Text = "working...";
- bool isDuplicate = false;
- string name = txtName.Text;
- string password = txtPassword.Text;
- string adress = txtAdress.Text;
- SqlDataReader reader = FetchWriteData("SELECT * FROM customer");
- while (reader.Read())
- {
- if (reader["name"].ToString() == name)
- {
- isDuplicate = true;
- lblError.Text = "That username is already in use";
- break;
- }
- }
- if (!isDuplicate)
- {
- SqlDataReader writer = FetchWriteData("INSERT INTO Customer(name, password, adress) VALUES('" + name + "', '" + password + "', '" + adress + "')");
- lblError.Text = "User registration complete!";
- Session["message"] = "Account Created! Please Log in";
- Response.Redirect("~/LogIn.aspx");
- }
- }
- private SqlDataReader FetchWriteData(string sql)
- {
- SqlConnection conn = new SqlConnection();
- conn.ConnectionString = WebConfigurationManager.ConnectionStrings["MinConn"].ConnectionString;
- conn.Open();
- SqlCommand cmd = new SqlCommand(sql, conn);
- SqlDataReader reader = cmd.ExecuteReader();
- return reader;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement