首页 新闻 搜索 专区 学院

过程或函数 'updateCourse' 需要参数 '@DepartmentID',但未提供该参数。

0
悬赏园豆:20 [已关闭问题]

存储过程:
ALTER PROCEDURE dbo.updateCourse

    @ID INT,
    @CourseID NVARCHAR(50),
    @CourseName nvarchar(50),
    @DepartmentID NVARCHAR(50),
    @RegTime datetime,
    @Note nvarchar(50)
    

AS
    UPDATE Course SET CourseName =@CourseName,Note =@Note,RegTime=@RegTime
    WHERE ID =@ID AND DepartmentID=@DepartmentID
    RETURN


[color=#FF00FF]调用方法:[/color]
  public override void updateObject(Course t)
        {
            SqlHelper.ExecuteNonQuery(connection, "dbo.updateCourse", t.Id, t.CourseID, t.CourseName,t.DepartmentID, t.RegTime,t.Note);
        }

前台:

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="CourseSource"
                    Width="100%" AllowPaging="True" DataKeyNames="Id,CourseID"
                    onrowdatabound="GridView1_RowDataBound">
                    <PagerSettings FirstPageText="首页" LastPageText="尾页" Mode="NextPreviousFirstLast"
                        NextPageText="下一页" PreviousPageText="上一页" />
                    <RowStyle HorizontalAlign="Center" VerticalAlign="Bottom" CssClass="line" />
                    <Columns>
                        <asp:BoundField DataField="Id" HeaderText="系统编号" SortExpression="Id" ReadOnly="True" />
                        <asp:BoundField DataField="CourseID" HeaderText="课程编号" SortExpression="CourseID"
                            ReadOnly="True" />
                        <asp:BoundField DataField="CourseName" HeaderText="课程名" SortExpression="CourseName" />
                        <asp:BoundField DataField="Note" HeaderText="备注" SortExpression="Note" />
                        <asp:BoundField DataField="RegTime" HeaderText="记录时间" SortExpression="RegTime"
                            DataFormatString="{0:d}" ReadOnly="True" />
                        <asp:CommandField HeaderText="修改" ShowEditButton="True" />
                        <asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" />
                    <PagerStyle BorderStyle="Groove" HorizontalAlign="Center"
                        VerticalAlign="Bottom" BackColor="#CCCCCC" />
                    <EmptyDataTemplate>
                        <center>
                            暂无数据!</center>
                    </EmptyDataTemplate>
                    <HeaderStyle BackColor="#9999FF" />
                </asp:GridView>
                <asp:ObjectDataSource ID="CourseSource" runat="server" DataObjectTypeName="Entity.Course"
                    DeleteMethod="deleteObject" SelectMethod="getList" TypeName="BLL.CAction.CourseAction"
                    UpdateMethod="updateObject">
                    <SelectParameters>
                        <asp:SessionParameter Name="name" SessionField="DepartmentID" Type="String" DefaultValue="JSJ" />
                    </SelectParameters>
                </asp:ObjectDataSource>


问题:

过程或函数 'updateCourse' 需要参数 '@DepartmentID',但未提供该参数。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.SqlClient.SqlException: 过程或函数 'updateCourse' 需要参数 '@DepartmentID',但未提供该参数。

源错误:


行 221:            
行 222:            //finally, execute the command.
行 223:            int retval = cmd.ExecuteNonQuery();
行 224:            
行 225:            // detach the SqlParameters from the command object, so they can be used again.
 

义_风的主页 义_风 | 初学一级 | 园豆:170
提问于:2010-05-15 12:30
< >
分享
其他回答(2)
0

那是因为从页面中取出的DepartmentId是空值,虽然你把SelectParameters的参数源设成了session,但是更新的时候并不会自动到session里取departmentid。可以在gridview的updating事件里写下面的代码:

string departmentId = Session["DepartmentID"].ToString();

e.NewValues.Add("DepartmentId",departmentId);

Hawkon | 园豆:225 (菜鸟二级) | 2010-05-15 15:34
0

1、code里的和存储过程参数不匹配,检查个数和拼写;

2、检查传值;

winzheng | 园豆:8797 (大侠五级) | 2010-05-19 13:47
0

确定SqlHelper.ExecuteNonQuery(connection, "dbo.updateCourse", t.Id, t.CourseID, t.CourseName,t.DepartmentID, t.RegTime,t.Note);这里DepartmentID参数传入了,如果确定有值就应该差不多啦

西越泽 | 园豆:10633 (专家六级) | 2010-05-22 22:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册