Q:

Wix - Msi :How to check if a particular row exists in a msi Data table or not

I want to check if a particular row exists in Data table or not.  
E.g., I want to check if Property Table Exists in msi data table or not.  If it exists then I want to check if "Property" column and "Value" column exists or not.  If both exists then I want to check if Property "ARPNOMODIFY" exists or not.  
                if (database. Tables. Contains("Property"))
                {
                    if (database. Tables["Property"].Columns. Contains("Property"))
                    {
                        // here I want to checked if "ARPNOMODIFY" or any other property exists or not.  If it exists then I want its value. 
                    }
                }

I have one data table having structure as( "TableName","ColumnNAme1","ColumnName2","Value at ColumnName1").  So for above record the row is like ("Property","Property","Value","ARPNOMODIFY") and I want to return Value 1 as ARPNOMODIFY exists and its value is 1.  
Now consider another row as ("Property","Propery","Value","ICFAGREE").  Now if ICFAGREE property doesn't exists in Property table then I want to return null string. 
Thanks in advance. 
Also Consider another row ("AdminExecuteSequence","Action","Condition","SetSpecifiedDir").  Now in this example AdminExecuteSequence table has Action and Condition columns.  One of value under Action columns is "SetSpecifiedDir" so its corresponding value under "Condition" column is "ORCADIR". So I want to return "ORCADIR" this string, If "SetSpecifiedDir" value exists in AdminExecuteSequence table or else I would return null. 

A:

DTF has rich classes to help you do these kinds of tests. 
Also see: MSI Tip: Authoring an ICE using C# / DTF
   using System;
    using Microsoft. Deployment. WindowsInstaller;

    namespace ConsoleApplication1
    {
        class Tester : IDisposable
        {
            Database _database;

            public Tester(string databasePath)
            {
                _database = new Database(databasePath, DatabaseOpenMode. ReadOnly);
            }

            public void Dispose()
            {
                _database. Dispose();
            }

            public bool HasTable(string tableName)
            {
                return _database. Tables. Contains(tableName);
            }

            public bool HasColumn(string tableName, string columnName)
            {
                bool columnExists = false;
                if (HasTable(tableName))
                {
                    columnExists = _database. Tables[tableName].Columns. Contains(columnName);
                }
                return columnExists;
            }

            public bool QueryReturnsData(string sqlStatement, params object[] args)
            {
                return QueryReturnsData(string. Format(sqlStatement, args));
            }

            public bool QueryReturnsData(string sqlStatement)
            {
                bool containsData = false;
                using (View view = _database. OpenView(sqlStatement))
                {
                    view. Execute();
                    using (Record rec = view. Fetch())
                    {
                        if(rec ! = null )
                        {
                            containsData = true;
                        }
                    }
                }
                return containsData;

            }

        }
    }

