Exemple #1
0
        /// <summary>
        /// Excete command string
        /// Close connection database
        /// </summary>
        /// <param name="cmdString"></param>
        /// <param name="conString"></param>
        /// <returns>string</returns>
        public static string BindDataCommand(string cmdString, string conString)
        {
            string result;

            using (var con = ConnectCache.DBUtils.GetDBConnection())
            {
                try
                {
                    con.Open();
                    using (var cmd = new CacheCommand(cmdString, con))
                    {
                        result = cmd.ExecuteScalar().ToString();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
                finally
                {
                    con.Close();
                    con.Dispose();
                }
            }

            return(result);
        }
Exemple #2
0
 private void CreateTableIfNotExists(List <string> tables, string tableName, CacheConnection connection)
 {
     if (tables.Count(x => x == tableName) == 0)
     {
         using (var command = new CacheCommand(GetTableQuery(tableName), connection))
             command.ExecuteScalar();
     }
 }
        public static string ExecuteScalarBindDataCommand(string cmdString, string connectionString)
        {
            string result = string.Empty;

            using (var con = new CacheConnection(connectionString))
            {
                using (var cmd = new CacheCommand(cmdString, con))
                {
                    con.Open();
                    result = Convert.ToString(cmd.ExecuteScalar());
                }
            }

            return(result);
        }
Exemple #4
0
        public static string BindDataCommand(string cmdString, string conString)
        {
            string result = string.Empty;

            using(var con = new CacheConnection(conString))
            {
                con.Open();
                using(var cmd = new CacheCommand(cmdString, con))
                {
                    result = cmd.ExecuteScalar().ToString();
                }
            }

            return result;
        }
Exemple #5
0
        private void CreateIndexesIfNotExist(CacheConnection connection)
        {
            using (CacheCommand checkUserIndex = new CacheCommand(CheckUserNameIndexQuery, connection),
                   checkRoleIndex = new CacheCommand(CheckRoleNameIndexQuery, connection))
            {
                if ((int)checkUserIndex.ExecuteScalar() == 0)
                {
                    using (var createUserIndex = new CacheCommand(UserNameIndexQuery, connection))
                        createUserIndex.ExecuteNonQuery();
                }

                if ((int)checkRoleIndex.ExecuteScalar() == 0)
                {
                    using (var createRoleIndex = new CacheCommand(RoleNameIndexQuery, connection))
                        createRoleIndex.ExecuteNonQuery();
                }
            }
        }
Exemple #6
0
        public static string BindDataCommand(string cmdString, CacheConnection con)
        {
            string result;

            try
            {
                using (var cmd = new CacheCommand(cmdString, con))
                {
                    result = cmd.ExecuteScalar().ToString();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result = string.Empty;
            }

            return(result);
        }