过程或函数usp_employee_update指定了太多参数

时间:2017-09-06 01:40:14

标签: sql asp.net

我正在使用存储过程来更新我的两个表:

employeesuseraccounts 但是,每当我更新表时,我都会收到此错误

  

过程或函数usp_employee_update指定了太多参数。

我正在使用devexpress gridview。我在rowupdating事件

下更新我的表

我的SqlDataSource

<asp:SqlDataSource ID="users" runat="server" ConnectionString="<%$ ConnectionStrings:WaterBillingConnectionString %>" SelectCommand="SELECT UserAccounts.UserID, Employees.FirstName, Employees.MiddleName, Employees.LastName, Employees.ContactNumber, UserAccounts.UserName, UserAccounts.Password, Ref_UserTypes.UserTypeCode FROM Employees INNER JOIN UserAccounts ON Employees.EmployeeID = UserAccounts.PersonID INNER JOIN Ref_UserTypes ON UserAccounts.UserTypeID = Ref_UserTypes.UserTypeID" UpdateCommand="usp_employee_update" UpdateCommandType="StoredProcedure">
     <UpdateParameters>
         <asp:SessionParameter Name="fname" SessionField="fname" />
         <asp:SessionParameter Name="lname" SessionField="lname" />
         <asp:SessionParameter Name="mname" SessionField="mname" />
         <asp:SessionParameter Name="contact" SessionField="contact" />
         <asp:SessionParameter Name="id" SessionField="id" />
         <asp:SessionParameter Name="uname" SessionField="uname" />
         <asp:SessionParameter Name="password" SessionField="password" />
         <asp:SessionParameter Name="uid" SessionField="uid" />
     </UpdateParameters>
 </asp:SqlDataSource>

存储过程

ALTER PROCEDURE [dbo].[usp_employee_update]
@fname varchar(50),@lname varchar(50), @mname varchar(50),@contact 
decimal(11,0), @id integer, @uname varchar(50), @password varchar(50), @uid 
integer  
AS
BEGIN
UPDATE       Employees 
SET                FirstName = @fname, LastName = @lname, MiddleName = 
@mname, ContactNumber = @contact
from Employees a join UserAccounts b on a.EmployeeID = b.PersonID 
WHERE        (UserID = @id)

UPDATE       UserAccounts
SET               UserName = @uname, Password = @password, UserTypeID = @uid
from Employees a join UserAccounts b on a.EmployeeID = b.PersonID 
WHERE        (UserID = @id)
commit

END

RowUpdating

protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        Session["id"] = e.Keys[0].ToString();
        Session["fname"] = e.NewValues[1].ToString();
        Session["mname"] = e.NewValues[2].ToString();
        Session["lname"] = e.NewValues[3].ToString();
        Session["contact"] = e.NewValues[4].ToString();
        Session["uname"] = e.NewValues[5].ToString();
        Session["password"] = e.NewValues[6].ToString();
        Session["uid"] = e.NewValues[7];

    }

gridview的

 <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="users" KeyFieldName="UserID" OnRowUpdating="ASPxGridView1_RowUpdating" style="font-size: large" Theme="MetropolisBlue" Width="100%">
                         <ClientSideEvents CustomButtonClick="OnCustomButton" />
                         <SettingsDetail ShowDetailRow="True" />
                         <Templates>
                             <DetailRow>
                                 <dx:ASPxGridView ID="ASPxGridView2" runat="server" AutoGenerateColumns="False" DataSourceID="logtrail" KeyFieldName="LogID" OnBeforePerformDataSelect="ASPxGridView2_BeforePerformDataSelect" style="margin-top: 0px" Theme="MetropolisBlue" Width="100%">
                                     <Columns>
                                         <dx:GridViewDataTextColumn FieldName="LogID" ReadOnly="True" VisibleIndex="0">
                                             <EditFormSettings Visible="False" />
                                         </dx:GridViewDataTextColumn>
                                         <dx:GridViewDataTextColumn FieldName="LogTrail" VisibleIndex="1">
                                         </dx:GridViewDataTextColumn>
                                         <dx:GridViewDataDateColumn FieldName="LogDate" VisibleIndex="2">
                                         </dx:GridViewDataDateColumn>
                                     </Columns>
                                 </dx:ASPxGridView>
                                 <asp:SqlDataSource ID="logtrail" runat="server" ConnectionString="<%$ ConnectionStrings:WaterBillingConnectionString %>" SelectCommand="SELECT [LogID], [LogTrail], [LogDate] FROM [LogSessions] WHERE ([UserID] = @UserID)">
                                     <SelectParameters>
                                         <asp:SessionParameter Name="UserID" SessionField="userid" Type="Int32" />
                                     </SelectParameters>
                                 </asp:SqlDataSource>
                             </DetailRow>
                         </Templates>
                         <SettingsSearchPanel Visible="True" />
                         <Columns>
                               <dx:GridViewCommandColumn ShowEditButton="True" ShowInCustomizationForm="True" VisibleIndex="0">
                                        <CustomButtons>
                                                <dx:GridViewCommandColumnCustomButton ID="btnDetails" Text="New" >
                                                </dx:GridViewCommandColumnCustomButton>
                                                  </CustomButtons>
                                             </dx:GridViewCommandColumn>

                             <dx:GridViewDataTextColumn FieldName="UserID" ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="1">
                             </dx:GridViewDataTextColumn>
                             <dx:GridViewDataTextColumn FieldName="FirstName" ShowInCustomizationForm="True" VisibleIndex="2">
                             </dx:GridViewDataTextColumn>
                             <dx:GridViewDataTextColumn FieldName="MiddleName" ShowInCustomizationForm="True" VisibleIndex="3">
                             </dx:GridViewDataTextColumn>
                             <dx:GridViewDataTextColumn FieldName="LastName" ShowInCustomizationForm="True" VisibleIndex="4">
                             </dx:GridViewDataTextColumn>
                             <dx:GridViewDataTextColumn FieldName="ContactNumber" ShowInCustomizationForm="True" VisibleIndex="5">
                             </dx:GridViewDataTextColumn>
                             <dx:GridViewDataTextColumn FieldName="UserName" ShowInCustomizationForm="True" VisibleIndex="6">
                             </dx:GridViewDataTextColumn>
                             <dx:GridViewDataTextColumn FieldName="Password" ShowInCustomizationForm="True" VisibleIndex="7">
                             </dx:GridViewDataTextColumn>
                             <dx:GridViewDataComboBoxColumn FieldName="UserTypeCode" ShowInCustomizationForm="True" VisibleIndex="8">
                                 <PropertiesComboBox DataSourceID="SqlDataSource3" TextField="UserTypeCode" ValueField="UserTypeID">
                                 </PropertiesComboBox>
                             </dx:GridViewDataComboBoxColumn>
                         </Columns>
                     </dx:ASPxGridView>

提前谢谢你。

1 个答案:

答案 0 :(得分:0)

乍一看,我发现您没有为SessionParameter部分中的每个UpdateParameters定义固定数据类型,还有一些在RowUpdating事件中分配了错误类型的值会立即触发“争论太多”。

首先,您需要在SessionParameter上设置与存储过程参数中定义的数据类型完全匹配的数据类型:

<asp:SqlDataSource ID="users" runat="server" ConnectionString="<%$ ConnectionStrings:WaterBillingConnectionString %>" SelectCommand="SELECT UserAccounts.UserID, Employees.FirstName, Employees.MiddleName, Employees.LastName, Employees.ContactNumber, UserAccounts.UserName, UserAccounts.Password, Ref_UserTypes.UserTypeCode FROM Employees INNER JOIN UserAccounts ON Employees.EmployeeID = UserAccounts.PersonID INNER JOIN Ref_UserTypes ON UserAccounts.UserTypeID = Ref_UserTypes.UserTypeID" UpdateCommand="usp_employee_update" UpdateCommandType="StoredProcedure">
     <UpdateParameters>
         <asp:SessionParameter Name="id" SessionField="id" Type="Int32" />
         <asp:SessionParameter Name="fname" SessionField="fname" Type="String" />
         <asp:SessionParameter Name="mname" SessionField="mname" Type="String" />
         <asp:SessionParameter Name="lname" SessionField="lname" Type="String" />
         <asp:SessionParameter Name="contact" SessionField="contact" Type="Decimal" />
         <asp:SessionParameter Name="uname" SessionField="uname" Type="String" />
         <asp:SessionParameter Name="password" SessionField="password" Type="String" />
         <asp:SessionParameter Name="uid" SessionField="uid" Type="Int32" />
     </UpdateParameters>
 </asp:SqlDataSource>

注意:如果您不确定,请为每个DbType="Int32"添加DbType="String"DbType="Decimal"SessionParameter,具体取决于参数数据类型。

其次,根据上面的预定义数据类型分配所有会话参数值:

protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
    Session["id"] = e.Keys[0]; // int
    Session["fname"] = e.NewValues[1].ToString(); // String
    Session["mname"] = e.NewValues[2].ToString(); // String
    Session["lname"] = e.NewValues[3].ToString(); // String
    Session["contact"] = Convert.ToDecimal(e.NewValues[4]); // decimal
    Session["uname"] = e.NewValues[5].ToString(); // String
    Session["password"] = e.NewValues[6].ToString(); // String
    Session["uid"] = e.NewValues[7]; // int
}

PS:对Convert.ToInt32int.Parse数组/索引器中存储的字符串值使用Convert.ToDecimaldecimal.Parse)或e.Keyse.NewValues)如果参数数据类型分别定义为intdecimal

之后,SessionParameter绑定应该有效。