Aspose.Words.Examples.CSharp.Mail_Merge.ExecuteWithRegionsDataTable.ExecuteDataTable C# (CSharp) Method

ExecuteDataTable() private static method

Utility function that creates a connection, command, Executes the command and return the result in a DataTable.
private static ExecuteDataTable ( string commandText ) : DataTable
commandText string
return System.Data.DataTable
        private static DataTable ExecuteDataTable(string commandText)
        {
            // Open the database connection.
            string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                RunExamples.GetDataDir_Database() + "Northwind.mdb";
            OleDbConnection conn = new OleDbConnection(connString);
            conn.Open();

            // Create and execute a command.
            OleDbCommand cmd = new OleDbCommand(commandText, conn);
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            DataTable table = new DataTable();
            da.Fill(table);

            // Close the database.
            conn.Close();

            return table;
        }
        // ExEnd:ExecuteWithRegionsDataTableMethods