private static IDBHelper CreateHelper() { IDBHelper _DBHelper = null; try { //使用指定的数据源,若DsName为空,则使用default _DBHelper = DBHelperManager.GetHelper(DsName); //取消指定 DsName = string.Empty; _DBHelper.Open(); return(_DBHelper); } catch (Exception ex) { if (ex.InnerException != null) { throw new DBOpenException(ex.InnerException.Message, ex); } else { throw new DBOpenException(ex); } } }
//app.config初始化 private void button6_Click(object sender, EventArgs e) { IDBHelper dbhelper = DBHelperManager.GetHelper("mysql"); try { dataGridView1.DataSource = dbhelper.ExecuteQuery("select * from wordlist_1"); // string sql = @"CREATE TABLE wordlist_1 ( // id INT(11) NOT NULL AUTO_INCREMENT, // word VARCHAR(50) DEFAULT NULL, // word_cn VARCHAR(50) DEFAULT NULL, // courseid TINYINT(4) DEFAULT NULL, // wordtype TINYTEXT, // PRIMARY KEY (id))"; // dbhelper.ExecuteNoQuery(sql); } catch (Exception) { throw; } finally { dbhelper.Close(); } }
/// <summary> /// 直接调用,访问default数据源 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button4_Click(object sender, EventArgs e) { //DataTable dt = DBHelper.ExecuteQuery("select * from ABST_User"); //dataGridView1.DataSource = dt; IDBHelper dbhelper = DBHelperManager.GetHelper(); dataGridView1.DataSource = dbhelper.ExecuteQuery("select * from ABST_User"); }
/// <summary> /// 使用默认配置文件初始化,App.config,Web.config /// </summary> static public void Configure() { XmlElement configElement = null; //读取App.config中的DataSourceConfig节点 configElement = System.Configuration.ConfigurationManager.GetSection("DataSourceConfig") as XmlElement; if (configElement == null) { throw new Exception("No Config Section [DataSourceConfig] Found in Default Config File or Config File Not Exist."); } DBHelperManager.DataSourceList = DBHelperManager.InitDS(configElement); }
/// <summary> /// 指定配置节点初始化 /// </summary> /// <param name="filePath"></param> static public void Configure(XmlNode node) { DBHelperManager.DataSourceList = DBHelperManager.InitDS(node); }
/// <summary> /// 指定配置节点初始化 /// </summary> /// <param name="filePath"></param> static public void Configure(XmlElement element) { DBHelperManager.DataSourceList = DBHelperManager.InitDS(element); }
/// <summary> /// 指定配置文件初始化 /// </summary> /// <param name="filePath"></param> static public void Configure(string filePath) { DBHelperManager.DataSourceList = DBHelperManager.InitDS(filePath); }
//private static Dictionary<string, IDBHelper> _All = new Dictionary<string, IDBHelper>(); ///// <summary> ///// 所有数据源 ///// </summary> //public static Dictionary<string, IDBHelper> All //{ // get // { // if (DBHelperManager.DBHelperCache == null || DBHelperManager.DBHelperCache.Count == 0) // { // XmlConfigurator.Configure(); // } // return DBHelperManager.DBHelperCache; // } // set // { // DBHelper2._All = value; // } //} public static IDBHelper Get(string dsName) { return(DBHelperManager.GetHelper(dsName)); }