Advertisement
felixbin

NewUser.aspx.cs

Mar 31st, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1.  using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Configuration;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Data;
  10.  
  11.  
  12.  
  13.  
  14. namespace TestGrounds
  15. {
  16.     public partial class NewUser : System.Web.UI.Page
  17.     {
  18.         protected void Page_Load(object sender, EventArgs e)
  19.         {
  20.  
  21.         }
  22.  
  23.         protected void btnRegisterUser_Click(object sender, EventArgs e)
  24.         {
  25.             lblError.Text = "working...";
  26.             bool isDuplicate = false;
  27.             string name     = txtName.Text;
  28.             string password = txtPassword.Text;
  29.             string adress   = txtAdress.Text;
  30.  
  31.             SqlDataReader reader = FetchWriteData("SELECT * FROM customer");
  32.  
  33.             while (reader.Read())
  34.             {
  35.                 if (reader["name"].ToString() == name)
  36.                 {
  37.                     isDuplicate = true;
  38.                     lblError.Text = "That username is already in use";
  39.                     break;
  40.                 }
  41.                    
  42.             }
  43.             if (!isDuplicate)
  44.             {
  45.                 SqlDataReader writer = FetchWriteData("INSERT INTO Customer(name, password, adress) VALUES('" + name + "', '" + password + "', '" + adress + "')");
  46.                 lblError.Text = "User registration complete!";
  47.                 Session["message"] = "Account Created! Please Log in";
  48.                 Response.Redirect("~/LogIn.aspx");
  49.             }
  50.         }
  51.  
  52.         private SqlDataReader FetchWriteData(string sql)
  53.         {
  54.             SqlConnection conn = new SqlConnection();
  55.  
  56.             conn.ConnectionString = WebConfigurationManager.ConnectionStrings["MinConn"].ConnectionString;
  57.  
  58.             conn.Open();
  59.  
  60.             SqlCommand cmd = new SqlCommand(sql, conn);
  61.  
  62.             SqlDataReader reader = cmd.ExecuteReader();
  63.  
  64.             return reader;
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement