Advertisement
Guest User

ASP coding for website error

a guest
Oct 17th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.SqlClient;
  8. using System.Configuration;
  9.  
  10. public partial class Index : System.Web.UI.Page
  11. {
  12.     protected void Page_Load(object sender, EventArgs e)
  13.     {
  14.         if(IsPostBack)
  15.         {
  16.             SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MemberInfoConnectionString"].ConnectionString);
  17.             conn.Open();
  18.             string checkuser = "select count(*) from SystemMemberInfo where Username="+ TextBoxUserName.Text +"'";
  19.             SqlCommand com = new SqlCommand(checkuser, conn);
  20.             int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
  21.             if (temp == 1)
  22.             {
  23.                 Response.Write("User already Exists");
  24.             }
  25.  
  26.             conn.Close();
  27.  
  28.         }
  29.     }
  30.     protected void Button1_Click(object sender, EventArgs e)
  31.     {
  32.         try
  33.         {
  34.             SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MemberInfoConnectionString"].ConnectionString);
  35.             conn.Open();
  36.             string insertQuery = "insert into SystemMemberInfo (Username,Email,Password,Minecraft Username) values (@Uname ,@email ,@password ,@mcuname)";
  37.             SqlCommand com = new SqlCommand(insertQuery, conn);
  38.             com.Parameters.AddWithValue("@Uname", TextBoxUserName.Text);
  39.             com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
  40.             com.Parameters.AddWithValue("@password", TextBoxPassword.Text);
  41.             com.Parameters.AddWithValue("@mcuname", TextBoxMcUserName.Text);
  42.  
  43.             com.ExecuteNonQuery();
  44.             Response.Redirect("WebsiteSystem.aspx");
  45.             Response.Write("Registration is successful.You can login now." );
  46.  
  47.  
  48.             conn.Close();
  49.         }
  50.         catch(Exception ex)
  51.         {
  52.             Response.Write("Error:"+ex.ToString());
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement