Exemple #1
0
        public IDBase CreateInitialDbClass(DBkind dbkind, DbOptKind optkind, DBConnectInfo info)
        {
            switch (optkind)
            {
            case DbOptKind.Oledb:
                oledbOptDbase = new OleDBase(dbkind, info);
                break;

#if UseOracle
            case DbOptKind.OracleClient:
                oralclientOptDbase = new OracleDbase(info);
                break;
#endif
            default:
                break;
            }
            IDBase result = null;
            if (optkind == DbOptKind.Oledb)
            {
                result = oledbOptDbase;
            }
#if UseOracle
            else
            {
                result = oralclientOptDbase;
            }
#endif
            return(result);
        }
 public OleDBase(DBkind dbkind, DBConnectInfo info)
 {
     mDBkind = dbkind;
     if (dbkind == DBkind.Access2003 || dbkind == DBkind.Access2007 || dbkind == DBkind.Access2013)
     {
         mConnectString = string.Format("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = {0};Persist Security Info=False; ", info.DataSource);
         //    mConnectString = string.Format("Provider = Microsoft.ACE.OleDB.15.0; Data Source = {0};Persist Security Info=False; ", info.DataSource);
     }
     else if (dbkind == DBkind.Oracle)
     {
         mConnectString = "Provider=msdaora; data source =  " + info.DataSource + "; user id = " + info.UserName + "; PassWord = "******"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + info.DataSource + "; Extended Properties=Excel 8.0";
     }
     else if (dbkind == DBkind.Sqlserver)
     {
         mConnectString = "Provider=SQLOLEDB;Data Source=" + info.DataSource + ";Initial Catalog= " + info.DatabaseName + ";UserId=" +
                          info.UserName + ";Password="******";";
     }
     OpenConnection(mConnectString);
 }
Exemple #3
0
        /// <summary>
        /// Format sql expression to query datetime.
        /// The sql expression used to query datetime differs in different types of databases.
        /// This method formats datetime querying expression for each of the databases.
        /// The formatted expression looks like: fieldname>='2001-1-1' and fieldname = '2011-1-1'"
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="dbkind"></param>
        /// <returns></returns>
        public static string FormatDateTime(string fieldName, DateTime start, DateTime end, DBkind dbkind)
        {
            string str = "";

            if (dbkind == DBkind.Sqlserver)
            {
                str = fieldName + ">='" + start.ToString() + "' and " + fieldName + "<='" + end.ToString() + "'";
            }
            else if (dbkind == DBkind.Access2003 || dbkind == DBkind.Access2007)
            {
                str = fieldName + ">=#" + start.ToString() + "# and " + fieldName + "<=#" + end.ToString() + "#";
            }
            return(str);
        }