Click here to Skip to main content
15,897,718 members
Articles / Programming Languages / C#
Article

BoneBoxes .Net Data Access Tools and Data Tier Generator

Rate me:
Please Sign up or sign in to vote.
3.18/5 (8 votes)
15 Nov 20022 min read 57.3K   837   33   1
BoneBoxes is a data access library that provides you with SQL statements and data validation based on the data set's properties

Introduction

BoneBoxes is a data access library. There are two connection objects available for the SQL and OleDb implementations. Both SqlConnecter and OleDbConnecter are IBoneConneter objects. They are both instantiated with a connection string. These objects handle database connections for you.

The BoneBoxes namespace also includes connection string structs. The OraDbString is not completely implemented. However the MsSqlDbString, MySqlDbString and OleDbString are implemented.

These are all just convenience classes for connection strings and database connections and simple interactions. The BoneBox class, however is the base class for the classes generated by the BoneBoxer class in the Generator namespace.

The generated BoneBoxes need only specify their data structure by implementing the abstract DataTable BuildStructure() method. All other functionality is in the BoneBox class. Each generated class represents a table in your database. Each object created from these classes, represents a row of that table's data. These are not to be considered as business objects. They only handle database interactions. These classes constitute a data access layer. Your applications should implement their own business objects layer and a translation layer between the two.

Generated BoneBoxes provide you with SQL statements and data validation based on the data set in their properties. However, you don't need to use this functionality as the BoneBoxes include methods for writing and deleting the data they represent. They include two constructors. One is the default, intended for adding new data. The other accepts an int primary key value, and an IBoneConnecter connection object to load the BoneBox from database data.

The BoneBoxes generater, can also produce a lite version of BoneBoxes. This lite version does not do data access. The lite version generates only properties based on a table's fields. These can then be modified to create a basis for business layer classes.

And for convenience, the generator can also produce typed collections along with your BoneBoxes.

BoneBoxes and it's generator are only convenience tools that I use. Therefore, BoneBoxes in it's present condition is totally free. All I ask is that you provide me with some feedback if the mood hits you. And of course, I accept no responsibility for any problems you may have with BoneBoxes. If you implement a mission critical application on top of BoneBoxes and something breaks, don't bring a multi million dollar lawsuit my direction. Likewise, I can't be held responsible if your children choke on the small pieces of broken BoneBoxes either.

Using the code

A brief description of how to use the article or code. The class names, the methods and properties, any tricks or tips.

using System;
using System.Data;
using System.Data.SqlClient;
using BoneSoft.MsgBrd.Sys;
using BoneSoft.BoneBoxes;

namespace BoneBoxes.Example {
    public class DataExample {
        private MsSqlDbstring dbs;
        private SqlConnecter conn;

        #region Example of IBoneConnecter and IBoneDbstring objects
        public DataExample() {
            dbs = new MsSqlDbstring("localhost", "Database", "uid", "pwd");
            conn = new SqlConnecter(dbs);
        }

        private DateTime GetLastPost(string sql) {
            IDataReader rs = conn.Select(sql);
            DateTime d = new DateTime(1901, 1, 1);
            if (rs.Read()) {
                d = rs.GetDateTime(0);
            }
            rs.Close();
            conn.Close();
            return d;
        }

        public SqlConnecter GetCopy(int id) {
            return (SqlConnecter) conn.MemberwiseClone();
        }
        #endregion

        // Example of using a generated BoneBox class called BbxCategory
        // from the BbxCategory database table
        public bool CreateCategory(Category cat) {
            BbxCategory BbxCat = new BbxCategory();
            BbxCat.Id = 1;
            BbxCat.Data = new DateTime();
            BbxCat.Name = "Cat1";
            return BbxCat.WriteBoneBox(conn) != 0 ? true : false;
        }
    }
}
/*  IBoneConnecter methods
    int Execute(string sql)
    IDataReader Select(string sql)
    DataSet SelectDataSet(string sql)
    DataTable SelectDataTable(string sql, string tbl)
    DataSet Schema()
    DataTable TableSchema(string table)
    Close()
*/

Points of Interest

The IBoneConnecter objects are basically simple connection managers that simplify connecting and querying. The IBoneDbstring objects are convenience structs for simplifying connection strings. The generated classes, can be used as is for interacting with your database. Just set their properties and tell them to write.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionDemo project ? Pin
Antonio Barros13-Feb-04 4:22
professionalAntonio Barros13-Feb-04 4:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.