我在数据库中有加密密码,问题是我尝试使用sql数据源更新gridview中的密码....."必须声明标量变量@password" messgae会显示出来。这是源代码。
<%@ Page Language="C#" MasterPageFile="~/menuMasterPage.master" AutoEventWireup="true" CodeFile="PasswordReset.aspx.cs" Inherits="fcrHome" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
<%
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
%>
<p>
<table style="width:100%;">
<tr>
<td colspan="3">
Password Reset Here</td>
</tr>
<tr>
<td style="width: 102px">
Oracle ID</td>
<td style="width: 143px">
<asp:TextBox ID="txtOracleid" runat="server" Width="140px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="txtoracleValidator" runat="server"
ControlToValidate="txtOracleid" ErrorMessage="Please Enter oracle Id"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="width: 102px; height: 9px">
</td>
<td style="width: 143px; height: 9px">
<asp:Button ID="btnSearch" runat="server" Text="Search" />
</td>
<td style="height: 9px">
</td>
</tr>
</table>
</p>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="UserPrivilegeId" DataSourceID="SqlDataSource2">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="UserName" HeaderText="UserName"
SortExpression="UserName" />
<asp:BoundField DataField="UserPrivilegeName" HeaderText="UserPrivilegeName"
SortExpression="UserPrivilegeName" />
<asp:BoundField DataField="UserPassword" HeaderText="UserPassword"
SortExpression="UserPassword" />
</Columns>
</asp:GridView>
<%
String password1= "select UserPassword FROM tblUserPrivileges WHERE UserName = @UserName";
Authentication authenticate = new Authentication();
String password= authenticate.Encryption(password1);
Response.Write(password);
%>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ATCF %>"
DeleteCommand="DELETE FROM [tblUserPrivileges] WHERE [UserPrivilegeId] = @UserPrivilegeId"
InsertCommand="INSERT INTO [tblUserPrivileges] ([UserName], [UserPrivilegeName], [UserPassword]) VALUES (@UserName, @UserPrivilegeName, @UserPassword)"
SelectCommand="SELECT [UserPrivilegeId], [UserName], [UserPrivilegeName], [UserPassword] FROM [tblUserPrivileges] WHERE ([UserName] = @UserName)"
UpdateCommand="UPDATE [tblUserPrivileges] SET [UserName] = @UserName, [UserPrivilegeName] = @UserPrivilegeName, [UserPassword] = @password ,[ModifiedDate] = getDate() WHERE [UserPrivilegeId] = @UserPrivilegeId">
<SelectParameters>
<asp:ControlParameter ControlID="txtOracleid" Name="UserName"
PropertyName="Text" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="UserPrivilegeId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserName" Type="Int32" />
<asp:Parameter Name="UserPrivilegeName" Type="String" />
<asp:Parameter Name="UserPassword" Type="String" />
<asp:Parameter Name="UserPrivilegeId" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="UserName" Type="Int32" />
<asp:Parameter Name="UserPrivilegeName" Type="String" />
<asp:Parameter Name="UserPassword" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</asp:Content>
How can i use variable in the sql data source ?
答案 0 :(得分:1)
<UpdateParameters>
<asp:Parameter Name="UserName" Type="Int32" />
<asp:Parameter Name="UserPrivilegeName" Type="String" />
<asp:Parameter Name="UserPassword" Type="String" />
<asp:Parameter Name="UserPrivilegeId" Type="Int32" />
</UpdateParameters>
您的参数名称是@UserPassword。
也许这就是问题。