kurtNeverDied
08-11-2009, 07:03 PM
OK,
I'm using Visual Web Developer in C#.
I'm trying to learn how to do my first full login/authentication/update details project using c#(pure code, no wizards).
Now....I slowly getting there(anyone know a good website to learn c#/ASP.net being a newbie?)
I'm stuck with the code-behind page for this one.
I'ts a simple update details page and I think I have to replace the existing email and password parametres with an update query in method in a class file in the AppCode folder.
Fields in Users table:
UserID- int
Email- varchar
Password- varchar
Any help will be greatly appreciated!!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="updateUser.aspx.cs" Inherits="updateUser" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Update Details</title>
<style type="text/css">
.style1
{
font-size: x-large;
font-weight: 700;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="style1">
Update Registration Details</div>
<br />
<br />
Old
Email:
<asp:TextBox ID="txtOldEmail" runat="server"></asp:TextBox>
<br />
New Email <asp:TextBox ID="txtNewEmail" runat="server"></asp:TextBox>
<br />
<p>
Old
Password:
<asp:TextBox ID="txtOldPassword" runat="server"></asp:TextBox>
<br />
New Password <asp:TextBox ID="txtNewPassword" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click"
Text="Update Member" />
</p>
</div>
</form>
</body>
</html>
Class file contains method used for login:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
/// <summary>
/// Summary description for dataAccess
/// </summary>
public class dataAccess
{
public Boolean insertUser(string Email, string Password)
{
SqlDataSource myDataSource = new SqlDataSource();
myDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["UserConnectionString"].ConnectionString.ToString();
myDataSource.InsertCommandType = SqlDataSourceCommandType.Text;
myDataSource.InsertCommand = "INSERT INTO Users (Email,Password) VALUES(@Email,@Password)";
myDataSource.InsertParameters.Add("Email", Email);
myDataSource.InsertParameters.Add("Password", Password);
int rowsAffected = 0;
try
{
rowsAffected = myDataSource.Insert(); // returns integer no of rows affected
}
catch (Exception e)
{
return false;
}
finally
{
myDataSource = null;
}
if (rowsAffected != 1)
return false;
else
return true;
}
public dataAccess()
{
//
// TODO: Add constructor logic here
//
}
}
I'm using Visual Web Developer in C#.
I'm trying to learn how to do my first full login/authentication/update details project using c#(pure code, no wizards).
Now....I slowly getting there(anyone know a good website to learn c#/ASP.net being a newbie?)
I'm stuck with the code-behind page for this one.
I'ts a simple update details page and I think I have to replace the existing email and password parametres with an update query in method in a class file in the AppCode folder.
Fields in Users table:
UserID- int
Email- varchar
Password- varchar
Any help will be greatly appreciated!!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="updateUser.aspx.cs" Inherits="updateUser" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Update Details</title>
<style type="text/css">
.style1
{
font-size: x-large;
font-weight: 700;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="style1">
Update Registration Details</div>
<br />
<br />
Old
Email:
<asp:TextBox ID="txtOldEmail" runat="server"></asp:TextBox>
<br />
New Email <asp:TextBox ID="txtNewEmail" runat="server"></asp:TextBox>
<br />
<p>
Old
Password:
<asp:TextBox ID="txtOldPassword" runat="server"></asp:TextBox>
<br />
New Password <asp:TextBox ID="txtNewPassword" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click"
Text="Update Member" />
</p>
</div>
</form>
</body>
</html>
Class file contains method used for login:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
/// <summary>
/// Summary description for dataAccess
/// </summary>
public class dataAccess
{
public Boolean insertUser(string Email, string Password)
{
SqlDataSource myDataSource = new SqlDataSource();
myDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["UserConnectionString"].ConnectionString.ToString();
myDataSource.InsertCommandType = SqlDataSourceCommandType.Text;
myDataSource.InsertCommand = "INSERT INTO Users (Email,Password) VALUES(@Email,@Password)";
myDataSource.InsertParameters.Add("Email", Email);
myDataSource.InsertParameters.Add("Password", Password);
int rowsAffected = 0;
try
{
rowsAffected = myDataSource.Insert(); // returns integer no of rows affected
}
catch (Exception e)
{
return false;
}
finally
{
myDataSource = null;
}
if (rowsAffected != 1)
return false;
else
return true;
}
public dataAccess()
{
//
// TODO: Add constructor logic here
//
}
}