ADO。net

ADO。net,第1张

概述using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.Common;using System.Configuration;using System.Data.SqlClient;using System
using System;using System.Collections.Generic;using System.linq;using System.Text;using System.Data;using System.Data.Common;using System.Configuration;using System.Data.sqlClIEnt;using System.Data.oleDb;using System.Data.Odbc;namespace readxml.DB{    public class DbHelper: IDbAction    {        private DbHelper()         {         }        enum DataProvIDer         {            sqlServer,oleDb,Odbc        }        private static DbHelper dbhelper;        private static object _lock = new object();        string connString = ConfigurationManager.AppSettings["DB_CONN_STR"];         public static DbHelper DBHelper         {            get             {                lock (_lock)                 {                    if (dbhelper == null)                    {                        dbhelper = new DbHelper();                    }                    return dbhelper;                }            }        }        /// <summary>        /// 获取数据库连接        /// </summary>        /// <param name="dp"></param>        /// <returns></returns>        private IDbConnection GetConnection(DataProvIDer dp)         {            switch (dp)            {                case DataProvIDer.sqlServer:                    {                        return new sqlConnection(connString);                    }                case DataProvIDer.Odbc:                     {                        return new OdbcConnection(connString);                    }                case DataProvIDer.oleDb:                     {                        return new oleDbConnection(connString);                    }                default:                    throw new Exception("xxxxxxxxxxxx");            }        }        /// <summary>        /// 打开数据库连接        /// </summary>        /// <param name="conn"></param>        private voID OpenConnection(IDbConnection conn)         {            conn.open();        }        /// <summary>        /// 数据查询        /// </summary>        /// <param name="sql"></param>        /// <returns></returns>        public Datatable Executequery(string sql)        {            DataSet ds = new DataSet();            try            {                sqlConnection conn = GetConnection(DataProvIDer.sqlServer) as sqlConnection;                OpenConnection(conn);                sqlCommand command = new sqlCommand(sql,conn);                sqlDataAdapter adapter = new sqlDataAdapter(command);                adapter.Fill(ds);                conn.Close();            }            catch (Exception e)            {                throw e;            }                        return ds.tables[0];        }    }}
总结

以上是内存溢出为你收集整理的ADO。net全部内容,希望文章能够帮你解决ADO。net所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1178756.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存