日期:2014-05-18  浏览次数:20761 次

将参数TxteBox转化为String失败,求指点!
C# code

            string sql = "insert into student(studentID,name,birthday,sex,password,discription) values (@ID,@NAME,@BIRTHDAY,@SEX,@PASSWORD,@DESCRIPTION)";

            SqlParameter[] parameters = new SqlParameter[6];

            SqlParameter id = new SqlParameter("@ID", SqlDbType.NChar);
            id.Value = this.txtCode;
            parameters[0] = id;

            SqlParameter name = new SqlParameter("@NAME", SqlDbType.NVarChar);
            name.Value = this.txtName.Text;
            parameters[1] = name;

            SqlParameter birthday = new SqlParameter("@BIRTHDAY", SqlDbType.DateTime);
            birthday.Value = DateTime.Parse(this.txtBrithday.Text);
            parameters[2] = birthday;

            SqlParameter sex = new SqlParameter("@SEX", SqlDbType.NChar);
            sex.Value = this.ddlSex.Text;
            parameters[3] = sex;

            SqlParameter password= new SqlParameter("@PASSWORD", SqlDbType.NVarChar);
            password.Value = this.txtCode;
            parameters[4] = password;

            SqlParameter description = new SqlParameter("@DESCRIPTION", SqlDbType.NVarChar);
            description.Value = this.txtDescription.Text;
            parameters[5] = description;

            try
            {
                bool result = dbHelper.ExecuteNonQuery(sql, parameters);
                Response.Write("<script type='text/javascript'> alert('添加成功');</script>");
                this.txtName.Text = "";
                this.txtCode.Text = "";
                this.txtBrithday.Text = "";
                this.txtDescription.Text = "";
            }
            catch (Exception ex)
            {
                Response.Write("<script type='text/javascript'> alert('添加失败,失败原因:" + ex.Message + "');</script>");
            }

将参数TxteBox转化为String失败,是不是birthday转换的时候出了问题?求指点

------解决方案--------------------
id.Value = this.txtCode;

这句错了,应该是:

id.Value = this.txtCode.Text;