• 类别操作.类


    namespace dal
    {
        public class olecado
        {
            private olehelp olehelper;

            public olecado()
            {
                olehelper = new olehelp();

            }
            /// <summary>
            /// 选出所有
            /// </summary>
            /// <returns>数据表</returns>
            public DataTable selectall()
            {
                return olehelper.execquery("select * from category", CommandType.Text);

            }
            /// <summary>
            /// 根据id选择
            /// </summary>
            /// <param name="id"></param>
            /// <returns></returns>
            public DataTable selectbyid(string id)
            {
                OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@id", id) };
                return olehelper.execquery("select * from category where id=@id", paras, CommandType.Text);
            }
            /// <summary>
            /// 根据内容选择
            /// </summary>
            /// <param name="catename"></param>
            /// <returns></returns>
            public DataTable selectbycatename(string catename)
            {
                OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@catename", catename) };
                return olehelper.execquery("select * from category where catename like '%'+@catename+'%'", paras, CommandType.Text);
            }
            /// <summary>
            /// 增加
            /// </summary>
            /// <param name="catename">名称</param>
            /// <returns>逻辑</returns>
            public bool insertcategory(string catename)
            {
                bool flag = false;
                string cmdtext = "insert into category(catename) values(@catename)";
                OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@catename", catename) };
                int res = olehelper.execnonquery(cmdtext, paras, CommandType.Text);
                if (res > 0)
                {
                    flag = true;
                }
                return flag;
            }
            /// <summary>
            /// 删除
            /// </summary>
            /// <param name="id"></param>
            /// <returns></returns>
            public bool deletecategory(string id)
            {
                bool flag = false;
                string cmdtext = "delete from category where id=@id";
                OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@id", id) };
                int res = olehelper.execnonquery(cmdtext, paras, CommandType.Text);
                if (res > 0)
                {
                    flag = true;
                }
                return flag;
            }
            /// <summary>
            /// 根据id更新
            /// </summary>
            /// <param name="id"></param>
            /// <param name="catename"></param>
            /// <returns></returns>
            public bool fixcategory(string catename, string id)
            {
                bool flag = false;
                string cmdtext = "update category set catename=@catename where id=@id";
                OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@catename", catename), new OleDbParameter("@id", id) };
                int res = olehelper.execnonquery(cmdtext, paras, CommandType.Text);
                if (res > 0)
                {
                    flag = true;
                }
                return flag;
            }
            /// <summary>
            /// 判断是否存在
            /// </summary>
            /// <param name="catename"></param>
            /// <returns></returns>
            public bool exist(string catename)
            {
                bool flag = false;
                OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@catename", catename) };
                DataTable dt = olehelper.execquery("select * from category where catename=@catename", paras, CommandType.Text);
                //DataTable dt = olehelper.execquery("select * from category where catename='" + catename + "'", CommandType.Text);
                if (dt.Rows.Count > 0)
                {
                    flag = true;
                }
                return flag;
            }

        }
    }

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Data.OleDb;
    天道酬勤,厚积薄发。 君子之行,静以修身,俭以养德。 非淡泊无以明志,非宁静无以致远。 如有恒,何须三更起,半夜眠;最怕莫,三天打鱼两天晒网,竹篮打水一场空。
  • 相关阅读:
    主机访问虚拟机网络服务失败
    关于接收者为指针的方法
    slice的部分说明
    ES基础知识
    静态语言和动态语言
    数据库设计三大范式
    SparkSQL小例子
    spark小例子
    spark 分析作者发布文章的总阅读量
    spark和hadoop差异
  • 原文地址:https://www.cnblogs.com/houweidong/p/2921291.html
Copyright © 2020-2023  润新知