sqldatasource里面的参数如下:<asp:SqlDataSource ID="Sql_dormitoryupdate" runat="server"
ConnectionString="<%$ ConnectionStrings:DormitorySystemConnectionString %>"
SelectCommand="seach_all_dormitory" SelectCommandType="StoredProcedure"
UpdateCommand="update_dormitory" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="seach" DefaultValue="%" Name="all"
PropertyName="Text" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="roomnumber" Type="String" />
<asp:Parameter Name="bednumber" Type="String" />
<asp:Parameter Name="upordown" Type="String" />
<asp:Parameter Name="areaname" Type="String" />
</UpdateParameters></asp:SqlDataSource>
后台代码如下: protected void transfers_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
this.Sql_dormitoryupdate.UpdateParameters["name"].DefaultValue = this.transfers.SelectedDataKey["Name"].ToString();
this.Sql_dormitoryupdate.UpdateParameters["roomnumber"].DefaultValue = this.transfers.SelectedDataKey["RoomNumber"].ToString();
this.Sql_dormitoryupdate.UpdateParameters["bednumber"].DefaultValue =this.transfers .SelectedDataKey ["BedNumber"].ToString ();
this.Sql_dormitoryupdate.UpdateParameters["upordown"].DefaultValue = this.transfers.SelectedDataKey["UpOrDowm"].ToString();
this.Sql_dormitoryupdate.UpdateParameters["areaname"].DefaultValue = this.transfers.SelectedDataKey["AreaName"].ToString(); this.Sql_dormitoryupdate.Update();
}
存储过程如下:
ALTER PROCEDURE [dbo].[update_dormitory]
@name nvarchar(50),
@roomnumber nvarchar(50),
@bednumber nvarchar(50),
@upordown nvarchar(50),
@areaname nvarchar(50)AS
BEGIN
declare @area_id int
select @area_id =ResourceID from DormitoryArea where AreaName =@areaname
update Dormitory
set Accommodation_ResourceID =6,
Name =@name,
Sex =NULL,
Company =NULL,
GraduateTime =NULL,
CheckinTime =NULL,
LeaveTime =NULL,
PhoneNumber =NULL,
Remark =NULL,
flgDeleted ='N'
where DormitoryArea_ResourceID=@area_id and RoomNumber =@roomnumber and BedNumber =@bednumber and UpOrDowm =@upordown
END
执行,出现为过程或函数 update_dormitory 指定了过多的参数。望高手指点,谢谢
------解决方案--------------------------------------------------------
在执行SQL语句前 设置断点
看看执行对象中的参数 设置了几个
------解决方案--------------------------------------------------------
设断点,或用try包含所有代码,catch里循环输出参数集中各参数名和参数值。
------解决方案--------------------------------------------------------
去掉
<UpdateParameters>
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="roomnumber" Type="String" />
<asp:Parameter Name="bednumber" Type="String" />
<asp:Parameter Name="upordown" Type="String" />
<asp:Parameter Name="areaname" Type="String" />
</UpdateParameters>
试试
------解决方案--------------------------------------------------------