-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeleteAccount.aspx.cs
45 lines (42 loc) · 1.4 KB
/
DeleteAccount.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class DeleteAccount : System.Web.UI.Page
{
SqlConnection con;
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("UserSettings.aspx");
}
protected void btnConfirm_Click(object sender, EventArgs e)
{
try
{
con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myConnectionString"].ToString());
con.Open();
//Create Delete query for current session user
string query = string.Format("DELETE FROM users WHERE user_name='{0}'", Session["UserName"]);
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
//Closing session and redirecting to the homepage
Session.Abandon();
Response.Redirect("~/Home.aspx");
}
catch (Exception ex)
{
lblError.Text = "A database error has occurred";
}
}
protected void Page_Load(object sender, EventArgs e)
{
if(Session["UserName"] == null)
Response.Redirect("~/SignIn.aspx");
}
}