Advertisement
Guest User

c sharp update login whatever

a guest
Mar 30th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.65 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. public partial class _Default : System.Web.UI.Page
  9. {
  10.     protected void Page_Load(object sender, EventArgs e)
  11.     {
  12.         Button3.Enabled = false;
  13.     }
  14.     protected void Button1_Click(object sender, EventArgs e)
  15.     {
  16.         SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\sachin\Documents\Visual Studio 2012\WebSites\WebSite9\App_Data\Database.mdf;Integrated Security=True ");
  17.         con.Open();
  18.         SqlCommand cmd = new SqlCommand("Select * from admin where username='" + TextBox1.Text + "'",con);
  19.        
  20.         SqlDataReader rdr = cmd.ExecuteReader();
  21.         if (rdr.Read())
  22.         {
  23.             TextBox2.Text = rdr[1].ToString();
  24.             TextBox3.Text = rdr[2].ToString();
  25.             TextBox4.Text = rdr[3].ToString();
  26.            // TextBox1.Enabled = false;
  27.             TextBox2.Enabled = false;
  28.             TextBox3.Enabled = false;
  29.             TextBox4.Enabled = false;
  30.         }
  31.         else
  32.         {
  33.             Response.Write("<script>alert('invalid username');</script>");
  34.         }
  35.  
  36.         con.Close();
  37.     }
  38.     protected void Button2_Click(object sender, EventArgs e)
  39.     {
  40.         SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\sachin\Documents\Visual Studio 2012\WebSites\WebSite9\App_Data\Database.mdf;Integrated Security=True ");
  41.         con.Open();
  42.         SqlCommand cmd = new SqlCommand("update admin
  43. set password='"+TextBox2.Text+"',email='"+TextBox3.Text+"',city='"+TextBox4.Text+"'
  44.        where username='"+TextBox1.Text+"'",con);
  45.         cmd.ExecuteNonQuery();
  46.         con.Close();
  47.        
  48.     }
  49.     protected void Button4_Click(object sender, EventArgs e)
  50.     {
  51.         Button3.Enabled = true;
  52.         TextBox2.Enabled = false;
  53.         TextBox3.Enabled = false;
  54.         TextBox4.Enabled = false;
  55.  
  56.  
  57.     }
  58.     protected void Button3_Click(object sender, EventArgs e)
  59.     {
  60.         SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\sachin\Documents\Visual Studio 2012\WebSites\WebSite9\App_Data\Database.mdf;Integrated Security=True ");
  61.         con.Open();
  62.         SqlCommand cmd = new SqlCommand("delete admin  where username='" + TextBox1.Text + "'", con);
  63.         cmd.ExecuteNonQuery();
  64.         con.Close();
  65.     }
  66.     protected void Button5_Click(object sender, EventArgs e)
  67.     {
  68.         TextBox2.Enabled = true;
  69.         TextBox3.Enabled = true;
  70.         TextBox4.Enabled = true;
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement