日期:2014-05-16  浏览次数:20875 次

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 =@title, content = @content, [Image]=@image, EducationTypeId = @TypeId, [DegreeNum] = @degreeNum  WHERE ID=@id";
                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();
                MultiView