By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,641 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

Probably the easiest thing in the world, but I cannot find anexample...

P: n/a
I'm a classic ASP/VbScript user, transitioning to c# and .NET. I'm
making a little PW change utility which does this:

1. User inputs an email address/username (into a textbox)
2. User inputs their current Password(into a textbox)
3. User presses a submit button
4. Server checks the value of the text in the currentPassword textbox
against the user's stored password in the DB. If they don't match,
then it displays an error.
5. Else, a Datagrid control returns their password for editing.

Now, there are many examples of the datagrid part, so I have steps
1,3, and 5 working. But for the other part, I need to---->

somehow assign the value of this sql query:
"SELECT Password FROM aspnet_Membership WHERE
aspnet_Membership.Email='" + emailID.Text + "'"
to a simple string variable, and
check that value against a textbox (placed in the code below as
'currentPassword', but it does nothing yet.

I know this should be dirt simple, but all the tutorials seem to get
super-excited about the various controls without ever giving a step-1,
simplest example of getting a single value from SQL and turning it
into a simple string variable :(. I don't need/want an array or a
recordset. I just need to grab this one piece of info as a validator.

Can anyone assist? I've been looking around the net for nearly a day,
embarrassingly.

Here's "my" code, which is modified from a good example I found:

----------------------------------------------
<%@ Page Language="C#" %>
<%@ Import Namespace ="System.Data.SqlClient" %>
<%@ Import Namespace ="System.Data" %>
<script language="C#" runat="server">
void Page_Load(object sender, EventArgs e)
{}
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand = "SELECT Password FROM
aspnet_Membership WHERE aspnet_Membership.Email='" + emailID.Text +
"'";
SqlDataSource1.UpdateCommand = "UPDATE aspnet_Membership SET
Password = @Password";
}
protected void GridView1_PageIndexChanged(object sender, EventArgs
e)
{
GridView1.DataSourceID = SqlDataSource1.ID;
SqlDataSource1.SelectCommand = "SELECT Password FROM
aspnet_Membership WHERE aspnet_Membership.Email='" + emailID.Text +
"'";
SqlDataSource1.UpdateCommand = "UPDATE aspnet_Membership SET
Password = @Password";
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender,
GridViewEditEventArgs e)
{
BindIt();

}

protected void GridView1_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
{

BindIt();
}

protected void BindIt()
{

GridView1.DataSourceID = SqlDataSource1.ID;
SqlDataSource1.SelectCommand = "SELECT Password FROM
aspnet_Membership WHERE aspnet_Membership.Email='" + emailID.Text +
"'";
SqlDataSource1.UpdateCommand = "UPDATE aspnet_Membership SET
Password = @Password";
GridView1.DataBind();
}

protected void GridView1_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
BindIt();
}
</script>

<!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 id="Head1" runat="server">
<title>Database Access Page</title>
</head>
<body style="font-family:arial,helvetica,sans-serif;">
<h3>Password Retrieval and Update Utility</h3>
<h5>for external, non-Hines Employees</h5>
<form id="form1" runat="server">
<div>
<table style="width: 469px">
<tr>
<td>
Enter your User ID (your email address)
<br />
<asp:TextBox ID="emailID" runat="server" Width="469px"
EnableViewState="true"></asp:TextBox>
<asp:TextBox ID="currentPassword" runat="server" Width="469px"
EnableViewState="true"></asp:TextBox>
</td></tr>
<tr><td style="width: 160px">
&nbsp;<asp:Button ID="Button1" runat="server" Text="Retrieve
your Password" Width="210px" OnClick="Button1_Click" /></td></tr>

<tr><td colspan="3"><asp:Label ID="lblMessage" runat="server"></
asp:Label></td></tr>
</table>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateDeleteButton="False"
AutoGenerateEditButton="True" CellPadding="4"
ForeColor="#333333" GridLines="None" Width="469px"
DataSourceID="SqlDataSource1" EnableSortingAndPagingCallbacks="false"
PageSize="5" OnPageIndexChanged="GridView1_PageIndexChanged"
OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowUpdating="GridView1_RowUpdating" >
<FooterStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#CC0000" Font-Bold="True"
ForeColor="White" HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand=""
UpdateCommand=""
DeleteCommand =""
ConnectionString="<%$ ConnectionStrings:db %>" />
</div>
</form>
</body>
</html>

------------------------------------------------------------
Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.