| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 619 人关注过本帖
标题:ASP中向数据库插入数据的问题!!
只看楼主 加入收藏
gokoyo
Rank: 1
来 自:江苏
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-10-12
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
ASP中向数据库插入数据的问题!!
本人是个业余爱好者,从网上荡了个OA办公系统源码,然后自己改哦了学习。现在遇到难处了希望大家多多指教
图片附件: 游客没有浏览图片的权限,请 登录注册

如图,提交下拉框中的数据提示出错,提示内容如下:
过程或函数 'departmentInsert' 需要参数 '@dept_parid',但未提供该参数。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 过程或函数 'departmentInsert' 需要参数 '@dept_parid',但未提供该参数。
源错误:
行 260:
行 261:            //finally, execute the command.
行 262:            int retval = cmd.ExecuteNonQuery();
行 263:            // detach the SqlParameters from the command object, so they can be used again.
 

文件代码如下:
protected void Button1_Click(object sender, EventArgs e)
    {
               
        //部门名称
        string bumen = this.TextBox1.Text;
        //上级部门ID
        //int parid = this.DropDownList1.DataValueField;
        int parid = Int32.Parse(this.DropDownList1.Text);
        //int parid = 3 ;

         if (bumen != "")
        {
            if (parid != 0)
            {
                department dp = new department();
                dp.dept_department = bumen;
                dp.dept_parid = parid;
               
                int i = departmentBLL.Insert(dp);
                if (i < 0)
                {
                    this.Response.Redirect("selectbm.aspx");
                }
            }
            else
            {
                this.Response.Write("<script>window.alert ('请选择上级部门')</script>");               
            }
        }
        else
        {
            this.Response.Write("<script>window.alert ('请您输入标题')</script>");
            this.TextBox1.Focus();
        }
    }

存储过程代码如下:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-------------------------------------------------------------
--参数说明
-------------------------------------------------------------
/*
@dept_id  部门id
@dept_department  部门名称
@dept_parid 上级部门代码
*/   
ALTER PROCEDURE [dbo].[departmentInsert]
    @dept_id int output,
    @dept_department varchar(50),
    @dept_parid int,
AS
    SET NOCOUNT ON
    insert into department
    (
        [dept_department],
        [dept_parid]
        
    )
    values
    (
        @dept_department,
        @dept_parid
        
    )
    set @dept_id=scope_identity();

    return @@error

Entity文件代码如下:
 public class department
    {
        #region 变量定义
        ///<summary>
        ///部门id
        ///</summary>
        private int _dept_id;
        ///<summary>
        ///部门名称
        ///</summary>
        private string _dept_department = String.Empty;
        ///<summary>
        ///上级部门id
        ///</summary>
        private int _dept_parid = String.Empty;
       ................
       #region 构造函数
        public department()
        {
        }
        public department
        (
            int dept_id,
            string dept_department,
            int dept_parid
        )
        {
            _dept_id = dept_id;
            _dept_department = dept_department;
            _dept_parid = dept_parid;
        }
        #endregion
        #region 公共属性
        ///<summary>
        ///部门id
        ///</summary>
        public int dept_id
        {
            get { return _dept_id; }
            set { _dept_id = value; }
        }
        ///<summary>
        ///部门名称
        ///</summary>
        public string dept_department
        {
            get { return _dept_department; }
            set { _dept_department = value; }
        }
        ///<summary>
        ///上级部门id
        ///</summary>
        public int dept_parid
        {
            get { return _dept_parid; }
            set { _dept_parid = value; }
        }
        .............

SqlServerDAL文件代码如下:
       #region -----------实例化接口函数-----------

        #region 添加
        /// <summary>
        /// 向数据库中插入一条新记录
        /// </summary>
        /// <param name="department">department实体对象</param>
        /// <returns></returns>
        public int Insert(department department)
        {
            string sqlCommand = "departmentInsert";
            int res;
            SqlParameter[] param ={
            new SqlParameter("@dept_id",SqlDbType.Int),
            new SqlParameter("@dept_department",SqlDbType.VarChar),
            new SqlParameter("@dept_parid",SqlDbType.Int),
            };
            param[0].Direction = ParameterDirection.Output;
            param[1].Value = department.dept_department;
            param[2].Value = department.dept_parid;
            res = SqlHelper.ExecuteNonQuery(Conn.SqlConn, CommandType.StoredProcedure, sqlCommand, param);
            department.dept_id = ((param[0].Value) == DBNull.Value) ? 0 : Convert.ToInt32(param[0].Value);
            return res;
        }
        /// <summary>
        /// 向数据库中插入一条新记录。带事务
        /// </summary>
        /// <param name="sp">事务对象</param>
        /// <param name="department">department实体对象</param>
        /// <returns></returns>
        public int Insert(SqlTransaction sp, department department)
        {
            string sqlCommand = "departmentInsert";
            int res;
            SqlParameter[] param ={
            new SqlParameter("@dept_id",SqlDbType.Int),
            new SqlParameter("@dept_department",SqlDbType.VarChar),
            new SqlParameter("@dept_parid",SqlDbType.Int)
            };
            param[0].Direction = ParameterDirection.Output;
            param[1].Value = department.dept_department;
            param[2].Value = department.dept_parid;
            res = SqlHelper.ExecuteNonQuery(sp, CommandType.StoredProcedure, sqlCommand, param);
            department.dept_id = ((param[0].Value) == DBNull.Value) ? 0 : Convert.ToInt32(param[0].Value);
            return res;
        }
        #endregion


我是实在搞不懂了,希望大大帮帮忙,看看到底是什么原因,我是初次注册上来的。20分全给大家了,谢谢了!
搜索更多相关主题的帖子: ASP 数据库 
2009-10-12 11:10
kai87691098
Rank: 2
等 级:论坛游民
帖 子:3
专家分:25
注 册:2009-10-14
收藏
得分:20 
'@dept_parid'很明显。你没给这个字段赋值。你看看SQl语句吧!跟一下!
2009-10-14 11:55
快速回复:ASP中向数据库插入数据的问题!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031918 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved