日期:2014-05-18 浏览次数:20808 次
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>"); }