This very helpful wrapper over ADO.NET has been released to NuGet free of charge and will soon be released as open source.  It is now and will forever be free to use.

At the moment, I have only included the .NET 4.0 binary for the moment, this will be remedied soon.  For the moment, create a .NET 4 application.

Here is some example code with comments on basic functionality, just to jump start you.

            //create a context to the database, this will allow us
            // to create objects of the correct type from the factory
            // as well as find out about things like quote prefix and
            // suffixes.  You may either choose a connectionstring and
            // provider name, or simply pass they "name" of a
            // connectionString entry in the config file.
            var context = new DatabaseContext("dsn");

            //create a container for the SQL and parameters etc.
            var sc = context.CreateSQLContainer();

            //write any sql, I am making sure to create it using
            //the providers quotes.  The SQLText property is a
            //StringBuilder, allowing for complext string manipulation
            sc.SQLText.AppendFormat(@"SELECT  {0}CategoryID{1}
  FROM {0}Categories{1}
    WHERE {0}CategoryID{1}=", context.QuotePrefix, context.QuoteSuffix);

            //create a parameter, automattically generating a name
            //and attaching it to sqlcontainer
            var p = sc.AddWithValue(DbType.Int32, 7);

            //append the name of the parameter to the SQL string
            //if the provider only supports positional parameters
            // that will be used.  However, if named parameters are
            // supported, the proper prefixing will be used with the
            //name.  For example, @parameter for SQL Server, and
            // arameterName for Oracle.

            //write the resulting SQL for examination by the programmer

            // get a datatable
            var dt = sc.ExecuteDataTable();

            // get the first row of the datatable
            var row = dt.GetFirstRow();

            //loop through and output all the data to the screen.
            foreach (var itm in dt.Columns.OfType())
                Console.WriteLine("{0}: {1}", itm.ColumnName, row[itm]);
Posted in Software | Leave a comment