示例#1
0
        public object GetObjectValue(StringBuilder sql, object[] param)
        {
            object          result = null;
            OleDbConnection conn   = (OleDbConnection)this.GetInstance();

            try
            {
                //打开连接
                conn.Open();
                OleDbCommand cmd = new OleDbCommand(sql.ToString(), conn);
                if (param != null)
                {
                    cmd.Parameters.AddRange(param);
                }
                result = cmd.ExecuteScalar();
            }
            catch (Exception e)
            {
                _logRecorder.WriteException(e);
            }
            finally
            {
                conn.Close();
            }
            return(result);
        }
示例#2
0
 /// <summary>
 /// 将扩展名由NT转换为DB
 /// </summary>
 /// <param name="strPath"></param>
 /// <returns></returns>
 //private string ConvertFileExtensionFromNTToDB(string strPath)
 //{
 //    string strResult = "";
 //    if (strPath.LastIndexOf('.') > 0)//
 //    {
 //        strResult = strPath.Substring(0, strPath.LastIndexOf('.')) + ".db";
 //    }
 //    else
 //    {
 //        strResult = strPath + ".db";
 //    }
 //    return strResult;
 //}
 /// <summary>
 /// 将扩展名由DB转换为NT
 /// </summary>
 /// <param name="strPath"></param>
 /// <returns></returns>
 //private string ConvertFileExtensionFromDBToNT(string strPath)
 //{
 //    string strResult = "";
 //    if (strPath.LastIndexOf('.') > 0)//
 //    {
 //        strResult = strPath.Substring(0, strPath.LastIndexOf('.')) + ".nt";
 //    }
 //    else
 //    {
 //        strResult = strPath + ".nt";
 //    }
 //    return strResult;
 //}
 /// <summary>
 /// 获取数据为连接对象
 /// </summary>
 /// <returns></returns>
 public System.Data.SQLite.SQLiteConnection GetInstance()
 {
     try
     {
         //在并发时,使用单一对象
         if (_db == null)
         {
             CreateDBFile();
             return(_db = new SQLiteConnection("Data Source=" + _connectionString));
         }
         else
         {
             lock (_locker)
             {
                 return(_db);
             }
         }
     }
     catch (Exception ex)
     {
         _logRecorder.WriteException(ex);
         return(null);
     }
 }