-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateprofile.aspx.cs
67 lines (61 loc) · 2.85 KB
/
updateprofile.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace RegisterLogin
{
public partial class updateprofile : System.Web.UI.Page
{
string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["fullname"].ToString();
Label2.Text = Session["dateofbirth"].ToString();
Label3.Text = Session["email"].ToString();
Label4.Text = Session["contact"].ToString();
TextBox1.Text = Label1.Text;
TextBox2.Text = Label2.Text;
TextBox3.Text = Label3.Text;
TextBox4.Text = Label4.Text;
HttpCookie cookie = Request.Cookies["UserInfo"];
Label5.Text = cookie["password"];
TextBox5.Text = Label5.Text;
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if(TextBox6.Text==null)
{
SqlCommand cmd = new SqlCommand("update user_info set fullname='" + TextBox1.Text.ToString() + "', dateofbirth='" + TextBox2.Text.ToString() + "', email='" + TextBox3.Text.ToString() + "', contact='" + TextBox4.Text.ToString() + "',password='" + TextBox5.Text.ToString() + "' where fullname='"+Label1.Text+"'", con);
cmd.Connection = con;
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Successfully updated your profile info. Go to your profile.');</script>");
}
else
{
SqlCommand cmd = new SqlCommand("update user_info set fullname='" + TextBox1.Text.ToString() + "', dateofbirth='" + TextBox2.Text.ToString() + "', email='" + TextBox3.Text.ToString() + "', contact='" + TextBox4.Text.ToString() + "',password='" + TextBox6.Text.ToString() + "' where fullname='" + Label1.Text + "'", con);
cmd.Connection = con;
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Successfully updated your profile info. Go to your profile.');</script>");
}
con.Close();
Response.Redirect("userprofile.aspx");
}
catch (Exception ex)
{
Response.Write("<script>alert(' " + ex.Message + "');</script>");
}
}
}
}