• 对数据库的操作


    /*
     * Desinged by Jim Hui(惠永亮)
     * Email :yonglianghui@163.com
     * QQ:23011599
     * Jiangsu China
     * 2010-04-11
    */

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;

    /// <summary>
    /// dbc 的摘要说明
    /// </summary>
    public class dbc
    {
        public dbc()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        static string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "/App_Data/IFuGood.mdb";
        static OleDbConnection con = new OleDbConnection(conStr);

        public static DataTable ExecuteTable(string commandText, OleDbParameter[] paras)
        {
            DataSet ds = new DataSet();
            try
            {
                con.Open();
                OleDbCommand cmd = new OleDbCommand(commandText, con);
                if (paras != null)
                {
                    foreach (OleDbParameter para in paras)
                    {
                        cmd.Parameters.Add(para);
                    }
                }
                OleDbDataAdapter dap = new OleDbDataAdapter(cmd);
                dap.Fill(ds);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.ToString());
            }
            finally
            {
                con.Close();
            }
            return ds.Tables[0];
        }

        public static void ExecuteNoQuery(string commandText, OleDbParameter[] paras)
        {
            try
            {
                con.Open();
                OleDbCommand cmd = new OleDbCommand(commandText, con);
                if (paras != null)
                {
                    foreach (OleDbParameter para in paras)
                    {
                        cmd.Parameters.Add(para);
                    }
                }

                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {

                throw new Exception(ex.ToString());
            }
            finally
            {
                con.Close();
            }

        }

        public static object ExecuteScalar(string commandText, OleDbParameter[] paras)
        {
            object obj = new object();
            try
            {           
                con.Open();
                OleDbCommand cmd = new OleDbCommand(commandText, con);
                if (paras != null)
                {
                    foreach (OleDbParameter para in paras)
                    {
                        cmd.Parameters.Add(para);
                    }
                }
                obj = cmd.ExecuteScalar();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                con.Close();
            }

            return obj;
        }

    }

  • 相关阅读:
    第一次 实习笔记
    docker 提示 Drive has not been shared 错误
    使用matplotlib画出log的图像
    python基础实现tcp文件传输
    django简单实现注册登录模块
    python使用消息队列RabbitMq(进阶)
    scrapy爬虫值Items
    redis常见配置redis.conf
    js实现往数组中添加非存在的对象,如果存在就改变键值。
    CSS之user-select——设置标签中的文字是否可被复制
  • 原文地址:https://www.cnblogs.com/Mac_Hui/p/2481507.html
Copyright © 2020-2023  润新知