当我在gridview中的某一行上单击“编辑”时,它会显示应该的数据。它显示了我希望看到它们的文本框,它允许我修改框中的数据。当我单击该行上的Update时,它会取消取消;页面重新填充而不保存任何数据更改。数据库也没有变化。
<%@ Page Title="Employee Lookup"Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="EmployeeLookup.aspx.cs" Inherits="WSC.EmployeeLookup" %>
<p>
<asp:Table ID="Table1" runat="server" CellPadding="5" Width="442px">
<asp:TableRow>
<asp:TableCell><asp:Button ID="NewUserButton" PostBackUrl="~/EmployeeInfo.aspx" runat="server" Text="New Employee" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
</p>
<p>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="eID"
AutoGenerateEditButton="True" DataSourceID="AccessDataSource2"
EmptyDataText="There are no data records to display." AllowSorting="True" AllowPaging="True">
<Columns>
<asp:BoundField DataField="eID" HeaderText="Employee ID" ReadOnly="True" SortExpression="eID" />
<asp:BoundField DataField="eFirstName" HeaderText="FirstName" SortExpression="eFirstName" />
<asp:BoundField DataField="eLastName" HeaderText="LastName" SortExpression="eLastName" />
<asp:TemplateField HeaderText="JobTitle" SortExpression="eJobTitle">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" width="50" runat="server" Text='<%# Bind("eJobTitle") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("eJobTitle") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dept Code" SortExpression="deptNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" width="50" runat="server" Text='<%# Bind("deptNumber") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("deptNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UserName" SortExpression="eUserName">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" width="50" runat="server" Text='<%# Bind("eUserName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("eUserName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password" SortExpression="ePassword">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" width="70" runat="server" Text='<%# Bind("ePassword") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text="*********"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="eEmail">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("eEmail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("eEmail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hire Date" SortExpression="eDateHire">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("eDateHire") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("eDateHire") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="securityID" SortExpression="securityID">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("securityID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("securityID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="ErrorMessageLabel" runat="server" Text="" ></asp:Label>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="C:\WSC\WSC\WSC\CIS470_Database.accdb"
SelectCommand="SELECT `eID`, `eFirstName`, `eLastName`, `eJobTitle`, `deptNumber`, `eUserName`, `ePassword`, `eEmail`, `eDateHire`, `securityID` FROM `Employee`"
UpdateCommand="UPDATE `Employee` SET `eFirstName` = ?, `eLastName` = ?, `eJobTitle` = ?, `deptNumber` = ?, `eUserName` = ?, `ePassword` = ?, `eEmail` = ?, `eDateHire` = ?, `securityID` = ? WHERE `eID` = ?">
<DeleteParameters>
<asp:Parameter Name="eID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="eFirstName" Type="String" />
<asp:Parameter Name="eLastName" Type="String" />
<asp:Parameter Name="eJobTitle" Type="String" />
<asp:Parameter Name="deptNumber" Type="String" />
<asp:Parameter Name="eUserName" Type="String" />
<asp:Parameter Name="ePassword" Type="String" />
<asp:Parameter Name="eEmail" Type="String" />
<asp:Parameter Name="ePhone" Type="String" />
<asp:Parameter Name="eDateHire" Type="DateTime" />
<asp:Parameter Name="eDateTerm" Type="DateTime" />
<asp:Parameter Name="securityID" Type="Int32" />
</UpdateParameters>
</asp:AccessDataSource>
</p>
答案 0 :(得分:0)
添加:
<asp:Parameter Name="eID" Type="Int32" />
要:
<UpdateParameters>
<asp:Parameter Name="eFirstName" Type="String" />
<asp:Parameter Name="eLastName" Type="String" />
<asp:Parameter Name="eJobTitle" Type="String" />
<asp:Parameter Name="deptNumber" Type="String" />
<asp:Parameter Name="eUserName" Type="String" />
<asp:Parameter Name="ePassword" Type="String" />
<asp:Parameter Name="eEmail" Type="String" />
<asp:Parameter Name="ePhone" Type="String" />
<asp:Parameter Name="eDateHire" Type="DateTime" />
<asp:Parameter Name="eDateTerm" Type="DateTime" />
<asp:Parameter Name="securityID" Type="Int32" />
</UpdateParameters>
并使用:
eFirstName = @eFirstName, ... WHERE eID = @eID"
而不是您在UpdateCommand中使用的内容。问题是您的参数必须以更新和删除命令中的@开头。然后他们将在
之间的参数很多<DeleteParameters></DeleteParameters>
和
<UpdateParameters></UpdateParameters>