Ejemplo n.º 1
0
        static public void SetUpdateDate(string databaseNameToUpdate, string tableNameUpdated, SQLDataBase anySqlDB)
        {
            try
            {
                // - Init -
                bool rowExist = false;

                // - Init SQL Query -
                string statement = "SELECT CASE WHEN EXISTS (SELECT * FROM [E2MKI-MasterData].dbo.TD_UpdateDate WHERE DatabaseName='{0}' AND TableName='{1}') THEN 1 ELSE 0 END";
                statement = string.Format(statement, databaseNameToUpdate, tableNameUpdated);

                // - Run SQL Query -
                if ((int)anySqlDB.ExecuteScalar(statement) == 1)
                {
                    rowExist = true;
                }

                // - If row exists Update else Insert -
                if (rowExist == true)
                {
                    statement = "UPDATE [E2MKI-MasterData].dbo.TD_UpdateDate SET UpdateDate=GETDATE() WHERE DatabaseName='{0}' AND TableName='{1}'";
                }
                else
                {
                    statement = "INSERT INTO [E2MKI-MasterData].dbo.TD_UpdateDate (DatabaseName, TableName, UpdateDate) VALUES ('{0}', '{1}', GETDATE())";
                }

                // - Prepare statement -
                statement = string.Format(statement, databaseNameToUpdate, tableNameUpdated);

                // - Execute Statement -
                anySqlDB.ExecuteNonQuery(statement);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error during SetUpdateDate()\n{0}", e.Message);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Check if a row match the WHERE criteria. (SQL Query / Include already the WHERE keyword)
 /// </summary>
 /// <param name="anyDB"></param>
 /// <param name="anyTableName"></param>
 /// <param name="whereClause"></param>
 /// <returns></returns>
 public static bool Exists(SQLDataBase anyDB, string tableName, string whereClause)
 {
     // - Return true if at least 1 line meat the where criteria -
     return((int)anyDB.ExecuteScalar(string.Format("SELECT CASE WHEN EXISTS (SELECT * FROM {0} WHERE {1}) THEN 1 ELSE 0 END", tableName, whereClause)) == 1);
 }