标题:执行添加时,出项这样的异常,这是怎么回事啊?
只看楼主
belong0204
Rank: 2
等 级:论坛游民
帖 子:66
专家分:30
注 册:2009-4-9
结帖率:73.33%
已结贴  问题点数:5 回复次数:3 
执行添加时,出项这样的异常,这是怎么回事啊?
#region 执行SqlCommand对象
        /// <summary>
        /// 执行SqlCommand对象
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns></returns>
        public int GetComm(string sql)
        {
            int res;
            SqlConnection conn = GetConn();
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            res = cmd.ExecuteNonQuery();
            conn.Close();
            return res;
        }
        #endregion



 #region 插入新纪录
        /// <summary>
        /// 插入一条新纪录
        /// </summary>
        /// <param name="name">姓名</param>
        /// <param name="pwd">密码</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool Insert(string name, string pwd)
        {

            string sql = "insert into Users(username,password) values(@name,@pwd)";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@name", name), new SqlParameter("@pwd", pwd) };
            SQLHelper sqlhelper = new SQLHelper();
            int res;
            res = sqlhelper.GetComm(sql);
            if (res > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        #endregion

string name = this.textBox1.Text;
            string pwd = this.textBox2.Text;
            DBOperate dbo = new DBOperate();
            bool flag = false;
flag = dbo.Insert(name, pwd);
 if (flag)
            {
                MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("添加失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
搜索更多相关主题的帖子: 出项 
2010-03-23 22:21
xiaxianlin
Rank: 2
等 级:论坛游民
帖 子:19
专家分:56
注 册:2010-3-12
得分:3 
你没有把SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@name", name), new SqlParameter("@pwd", pwd) };这个参数传到sql语句里去啊
2010-03-23 22:29
belong0204
Rank: 2
等 级:论坛游民
帖 子:66
专家分:30
注 册:2009-4-9
得分:0 
刚看到,已经改过来了,还是要谢谢你,这么积极,兄弟,感谢你啊。
2010-03-23 22:30
xiaxianlin
Rank: 2
等 级:论坛游民
帖 子:19
专家分:56
注 册:2010-3-12
得分:0 
不用,大家一起学习
2010-03-23 22:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-300347-1-1.html




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

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