在我的项目(使用C#的Asp.net网站)中,我有一个连接到sqlserevrDataSource的formview。 因为使用为sqlDataSource配置指定自定义sql语句,我无法使用高级按钮进行活动的插入,更新,删除。现在为我的数据源添加更新功能,我手动在源代码中添加UpdateCommand,但它有一个错误说:
Invalid column name 'Email'.
Invalid column name 'IsApproved'.
Invalid column name 'IsLockedOut'.
Invalid column name 'LastLockoutDate'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPageAdmin.master" AutoEventWireup="true" CodeFile="edit-user.aspx.cs" Inherits="edit_user" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:FormView ID="FormView1" runat="server" DefaultMode="Edit" DataSourceID="SqlDataSource1">
<EditItemTemplate>
UserName:
<asp:TextBox ID="UserNameTextBox" runat="server" Text='<%# Bind("UserName") %>' />
<br />
LastActivityDate:
<asp:TextBox ID="LastActivityDateTextBox" runat="server" Text='<%# Bind("LastActivityDate") %>' />
<br />
Email:
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
<br />
IsApproved:
<asp:CheckBox ID="IsApprovedCheckBox" runat="server" Checked='<%# Bind("IsApproved") %>' />
<br />
IsLockedOut:
<asp:CheckBox ID="IsLockedOutCheckBox" runat="server" Checked='<%# Bind("IsLockedOut") %>' />
<br />
LastLockoutDate:
<asp:TextBox ID="LastLockoutDateTextBox" runat="server" Text='<%# Bind("LastLockoutDate") %>' />
<br />
UserId:
<asp:TextBox ID="UserIdTextBox" runat="server" Text='<%# Bind("UserId") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
UserName:
<asp:TextBox ID="UserNameTextBox" runat="server" Text='<%# Bind("UserName") %>' />
<br />
LastActivityDate:
<asp:TextBox ID="LastActivityDateTextBox" runat="server" Text='<%# Bind("LastActivityDate") %>' />
<br />
Email:
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
<br />
IsApproved:
<asp:CheckBox ID="IsApprovedCheckBox" runat="server" Checked='<%# Bind("IsApproved") %>' />
<br />
IsLockedOut:
<asp:CheckBox ID="IsLockedOutCheckBox" runat="server" Checked='<%# Bind("IsLockedOut") %>' />
<br />
LastLockoutDate:
<asp:TextBox ID="LastLockoutDateTextBox" runat="server" Text='<%# Bind("LastLockoutDate") %>' />
<br />
UserId:
<asp:TextBox ID="UserIdTextBox" runat="server" Text='<%# Bind("UserId") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
UserName:
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Bind("UserName") %>' />
<br />
LastActivityDate:
<asp:Label ID="LastActivityDateLabel" runat="server" Text='<%# Bind("LastActivityDate") %>' />
<br />
Email:
<asp:Label ID="EmailLabel" runat="server" Text='<%# Bind("Email") %>' />
<br />
IsApproved:
<asp:CheckBox ID="IsApprovedCheckBox" runat="server" Checked='<%# Bind("IsApproved") %>' Enabled="false" />
<br />
IsLockedOut:
<asp:CheckBox ID="IsLockedOutCheckBox" runat="server" Checked='<%# Bind("IsLockedOut") %>' Enabled="false" />
<br />
LastLockoutDate:
<asp:Label ID="LastLockoutDateLabel" runat="server" Text='<%# Bind("LastLockoutDate") %>' />
<br />
UserId:
<asp:Label ID="UserIdLabel" runat="server" Text='<%# Bind("UserId") %>' />
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:akhbarrConnectionString %>"
SelectCommand="SELECT aspnet_Users.UserName, aspnet_Users.LastActivityDate, aspnet_Membership.Email, aspnet_Membership.IsApproved, aspnet_Membership.IsLockedOut, aspnet_Membership.LastLockoutDate, aspnet_Users.UserId FROM aspnet_Users INNER JOIN aspnet_Membership ON aspnet_Membership.UserId = aspnet_Users.UserId WHERE (aspnet_Users.UserName = @UserName)"
updatecommand="update [aspnet_Users] set [UserName] =@UserName , [LastActivityDate]= @LastActivityDate , [Email]= @Email , [IsApproved] = @IsApproved , [IsLockedOut] = @IsLockedOut , [LastLockoutDate] = @LastLockoutDate , [UserId]= @UserId from aspnet_Users INNER JOIN aspnet_Membership ON aspnet_Membership.UserId = aspnet_Users.UserId">
<UpdateParameters>
<asp:Parameter Name="UserName" Type="string" />
<asp:Parameter Name="LastActivityDate" Type="DateTime" />
<asp:Parameter Name="Email" Type="string" />
<asp:Parameter Name="IsApproved" Type="Boolean" />
<asp:Parameter Name="IsLockedOut" Type="Boolean" />
<asp:Parameter Name="LastLockoutDate" Type="DateTime" />
<asp:Parameter Name="UserId" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="UserName" QueryStringField="UserName" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
答案 0 :(得分:2)
此错误仅表示您尝试在某些不包含这些列的数据表上运行命令。您需要确保更新命令正确。复制您尝试运行的命令,并在sql server management studio中直接针对您的数据库运行。
答案 1 :(得分:1)
您无法通过此查询更新两个表。据我了解你的
'Email',
'IsApproved'.
'IsLockedOut'.
'LastLockoutDate'
列属于表aspnet_Membership
,您正在使用查询
update [aspnet_Users] set [UserName] =@UserName , [LastActivityDate]= @LastActivityDate ,
[Email]= @Email , [IsApproved] = @IsApproved , [IsLockedOut] = @IsLockedOut ,
[LastLockoutDate] = @LastLockoutDate , [UserId]= @UserId from aspnet_Users INNER JOIN
aspnet_Membership ON aspnet_Membership.UserId = aspnet_Users.UserId
它只更新表aspnet_Users的列。
修改 -
update [aspnet_Users] set [UserName] =@UserName , [LastActivityDate]=
@LastActivityDate Where [UserId]=@userId
和
update [aspnet_Membership] set [Email]= @Email , [IsApproved] = @IsApproved ,
[IsLockedOut] = @IsLockedOut , [LastLockoutDate] = @LastLockoutDate where UserId= @UserId