Advertisement
felixbin

MyAccount.aspx.cs

Mar 31st, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 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. namespace TestGrounds
  12. {
  13.     public partial class MyAccount : System.Web.UI.Page
  14.     {
  15.         protected void Page_Load(object sender, EventArgs e)
  16.         {
  17.  
  18.         }
  19.         protected void btnGet_Click(object sender, EventArgs e)
  20.         {
  21.             string user = Session["user"].ToString();
  22.             string sql = "SELECT * FROM Customer";
  23.             SqlDataReader reader = FetchWriteData(sql);
  24.             while (reader.Read())
  25.             {
  26.                 if (user == reader["name"].ToString())
  27.                 {
  28.                     txtName.Text = reader["name"].ToString();
  29.                     txtPassword.Text = reader["password"].ToString();
  30.                     txtAdress.Text = reader["adress"].ToString();
  31.                 }
  32.             }
  33.         }
  34.  
  35.         private SqlDataReader FetchWriteData(string sql)
  36.         {
  37.             SqlConnection conn = new SqlConnection();
  38.             conn.ConnectionString = WebConfigurationManager.ConnectionStrings["MinConn"].ConnectionString;
  39.             conn.Open();
  40.             SqlCommand cmd = new SqlCommand(sql, conn);
  41.             SqlDataReader reader = cmd.ExecuteReader();
  42.             return reader;
  43.         }
  44.  
  45.         protected void btnUpdate_Click(object sender, EventArgs e)
  46.         {
  47.             string sql = "UPDATE customer SET name = '" + txtName.Text + "', password = '" + txtPassword.Text + "', adress = '" + txtAdress.Text + "' WHERE name = '" + Session["user"].ToString() + "'";
  48.             SqlDataReader reader = FetchWriteData(sql);
  49.             lblError.Text = "Information updated.";
  50.             Session["user"] = txtName.Text;
  51.             //lblError.Text = sql;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement