首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

将参数TxteBox转化为String失败,求指点!该怎么解决

2012-06-02 
将参数TxteBox转化为String失败,求指点!C# codestring sql insert into student(studentID,name,birthd

将参数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;

热点排行