当前位置: 代码迷 >> Access >> access添加和更新语句出有关问题
  详细解决方案

access添加和更新语句出有关问题

热度:175   发布时间:2016-05-06 02:27:56.0
access添加和更新语句出问题
最近sql server转过来。。sql语句有时候出什么错都不知道。昨天就是一个时间类型搞昏了头,
增加代码
C# code
private int id;        public int Id        {            get { return id; }            set { id = value; }        }        private string title;        public string Title        {            get { return title; }            set { title = value; }        }        private string image;        public string Image        {            get { return image; }            set { image = value; }        }//外键表        private EducationType educationType = new EducationType();        public EducationType EducationType        {            get { return educationType; }            set { educationType = value; }        }        private string content;        public string Content        {            get { return content; }            set { content = value; }        }        private int degreeNum;        public int DegreeNum        {            get { return degreeNum; }            set { degreeNum = value; }        }

方法
C# code
         /// <summary>        /// 增加行业研究文章        /// </summary>        /// <param name="education"></param>        /// <returns></returns>        public static int AddEducation(Education education)        {            string sql = "INSERT INTO [Education] ( title, content, [Image], EducationTypeId, DegreeNum ) values (@title,@content,@image,@typeId,@degreeNum)";            OleDbParameter[] paras ={new OleDbParameter("@title",education.Title),new OleDbParameter("@typeId",education.EducationType.Id),                                     new OleDbParameter("@content",education.Content),new OleDbParameter("@degreeNum",education.DegreeNum),                                     new OleDbParameter("@image",education.Image)};            return DBHelper.ExecuteNonQuery(sql,paras);        }        /// <summary>        /// 根据文章ID修改行业研究文章信息        /// </summary>        /// <param name="education"></param>        /// <returns></returns>        public static int UpdateEducationById(Education education)        {                            string sql = "UPDATE Education SET title [email protected], content = @content, [Image][email protected], EducationTypeId = @TypeId, [DegreeNum] = @degreeNum  WHERE [email protected]";                OleDbParameter[] paras ={new OleDbParameter("@title",education.Title),new OleDbParameter("@TypeId",education.EducationType.Id),                                     new OleDbParameter("@content",education.Content),new OleDbParameter("@degreeNum",education.DegreeNum),                                    new OleDbParameter("@id",education.Id),new OleDbParameter("@image",education.Image)};                return DBHelper.ExecuteNonQuery(sql, paras);                    }

界面后台
C# code
 /// <summary>    /// 修改    /// </summary>    /// <param name="sender"></param>    /// <param name="e"></param>    protected void Button3_Click(object sender, EventArgs e)    {        Education education = (Education)Session["education"];        education.Title = TextBox4.Text;        education.Content = FCKeditor2.Value;                   int i = EducationManage.UpdateEducationById(education);            if (i > 0)            {                DB();                MultiView1.Visible = false;            }                else        {            Response.Write("<script>alert('更新失败!');window.location='Error.aspx'</script>");        }       }     /// <summary>    /// 添加    /// </summary>    /// <param name="sender"></param>    /// <param name="e"></param>    protected void Button2_Click(object sender, EventArgs e)    {        string Images = "~/admin/educationImage/" + UpLoad.UpLoadImage(this.File1, "~/admin/educationImage/", "small_", 80, 60);        //过滤文本框内容        Images = InputText(Images, Images.Length);        if (Images == "~/admin/educationImage/没有选择上传图片")        {            Response.Write("<script>alert('请插入图片')</script>");            Response.Redirect("Error.aspx");        }        Education education = new Education();        education.Title = txt_title.Text;        education.Content = FCKeditor1.Value;        education.Image = Images;        education.EducationType.Id = Convert.ToInt32(DropDownList1.SelectedValue);        education.DegreeNum = 0;        int i = EducationManage.AddEducation(education);        if (i > 0)        {            Response.Write("<script language='javascript'>alert('添加新闻成功!')</script>");            DB();            Response.Redirect("educationManage.aspx");        }        else        {            Response.Redirect("Error.aspx");        }    }
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Sat Feb 25 14:52:37 CST 2017
  • 最近登录:Sat Feb 25 14:52:37 CST 2017
  • 最近登录:Sat Feb 25 14:52:37 CST 2017
  • 最近登录:Sat Feb 25 14:52:37 CST 2017
  • 最近登录:Sat Feb 25 14:52:37 CST 2017