SQL Helper

For Database Lover

Overview

What is SQL Helper?

I'm sharing this with the world because we need another way to access data - don't you think? Truthfully - I wanted to see if I could flex the C# stuff and run up data access with a single dll and signle line of functions.

Features

  • Fetch data with signle line of functions
  • Fetch data with custome column's name
  • Fetch data with sorting
  • Fetch data with diffrent type of joins
  • Fetch data with paging
  • SQL error handling
  • Full dll source code - (You can customize as your own way)
  • Development time saving... :)

Installation

You require to just add AjSqlHelper.dll into your bin folder and web.config setting. Done!

Web.Config file settings

<connectionStrings>
    <add name="ConnectionString" connectionString="[Your Connection String]"/>
</connectionStrings>

In web.config file this Connection String with name "ConnectionString" SQL Helper DLL will take automatically from file.

Documentation

Use the following reference to help you learn about each of the classes and funcations

What is use of MyResult class?

MyResult is very usefull class. It is very important class for understanding. Mostly every function will return this class with diffrent type of data.

MyResult will profile following data as per requirement.

  • AffectedRows: Provide result of affected rows with transaction
  • IsSuccess: Provide result of wether transaction is succeed or not
  • Message: Provide message of success of error (This is header of message or it self message)
  • DetailMessages: It will provide multiple detail of errors
  • DetailError: You can manage error handling here with below property Even you can send mail or some database entry from here for error handling perpose.
  • dsetData: Provide multiple DataTable with result
  • paging: Paging class will provide detail paging data
    • TotalRecords: Total number of records with the execute query
    • TotalPages: Total number of pages with the execute query
    • PageSize: Provide number of page size
    • PageIndex: First record index of current page
    • FirstRecordIndex: First record index of current page
    • LastRecordIndex: Last record index of current page
    • SortField: Provide default sort field or provided sort field from funcation
    • SortType: Provide default sort type or provided sort field from funcation

SQLHelper - Fetch Multiple Tables

SQLHelper - Fetch Data With Stored Procedure or only Execute Stored Procedure - Without Parameters

  • Just pass your srore procedure's name with GetTableBySP funcation. Your procedure should not have any parameters.
    You can fetch data or just execute your store procedure

    MyResult result = SqlHelper.GetTableBySP("YourStoreProcedureName");

SQLHelper - Fetch Data With Stored Procedure With Parameters

  • You can fetch data with your own function and pass sql parameters to like below function

    public DataSet OwnFunction(int ID, string Name)
    {
        DataSet dsetData = new DataSet();
    
        SqlParameter[] sqlParams = new SqlParameter[2];
        sqlParams[0] = DbParameter("@ID", ID);
        sqlParams[1] = DbParameter("@Name", Name);
        dsetData = ExecuteDataset(CommandType.StoredProcedure, "YourStoreProcedureName", sqlParams);
    
        return dsetData;
    }
    

dTable - Get Data With Different Criteria

dTable class has following parameter for functions.
Kindly first take a look with it so you can eaily understand all methods.

  • TableName: Provide table name or SQL View name
  • Columns: Provide column name saparate by comma (as per our sql select query)
  • Where: Provide where caluse
  • Sort: Provide sort column name
  • SortType: Provide sort type (ASC or DESC)
  • PageIndex: Provide current page index
  • PageSize: Provide page size

Note: You can't make join with this dTable class. If you want to do transaction with joins then please make SQL views or use jTable class.

You can fetch data with diffrent criteria. Ex. Custome columns, Column sorting and paging.

  • Select All Rows With All function

    MyResult result = dTable.All("TableName");
  • Fetch data with Select function

    MyResult result = dTable.Select("TableName");
    MyResult result = dTable.Select("TableName", "Columns");
    MyResult result = dTable.Select("TableName", "Columns", "Where");
    MyResult result = dTable.Select("TableName", "Columns", "Sort", "SortType");
    MyResult result = dTable.Select("TableName", "Columns", "Where", "Sort", "SortType");
    

    Select function is very usefull and it has five overload methods.
    All parameters description is above this function.

  • Fetch data with Where function

    MyResult result = dTable.Where("TableName", "Where");
    MyResult result = dTable.Where("TableName", "Where", "Columns");
    MyResult result = dTable.Where("TableName", "Where", "Columns", "Sort", "SortType");
    
  • Fetch data with OrderBy function

    MyResult result = dTable.OrderBy("TableName", "Sort", "SortType");
    MyResult result = dTable.OrderBy("TableName", "Sort", "SortType", "Columns");
    MyResult result = dTable.OrderBy("TableName", "Sort", "SortType", "Columns", "Where");
    
  • Fetch data with Paged function

    MyResult result = dTable.Paged("TableName", "PageIndex", "PageSize");
    MyResult result = dTable.Paged("TableName", "PageIndex", "PageSize", "Columns");
    MyResult result = dTable.Paged("TableName", "PageIndex", "PageSize", "Columns", , "Where");
    MyResult result = dTable.Paged("TableName", "PageIndex", "PageSize", "Columns", , "Where", "Sort", "SortType");
    

    You can fetch data with paging and you paging result will return with MyResult class.
    PageIndex you require to pass your current page index. which you require to show in list.
    PageSize pass your current page size.

jTable - Get Data With Different Criteria and Joins

jTable class has two constroctor. one has pass only table name which is same as only dTable class.
Second one is SqlJoin class. SqlJoin class has following parameters

Info: All dTable and jTable class has same method only diffrent is joins and jTable class has own constructor while dTable class has all methods are static.

Following are some Example for how to use jTable calss.

  • Simple Select method with jTable class with single join
    MyResult result = new jTable("Student",
                new SqlJoin(SqlJoinType.Left, "Class", "ID", "Student", "ClassID"))
                .Select("Student.ID, Student.Name, Class.Name, Student.DOB");
    
  • Simple Select method with jTable class with multiple join
    MyResult result = new jTable("Student",
                new SqlJoin(SqlJoinType.Left, "Class", "ID", "Student", "ClassID"),
                new SqlJoin(SqlJoinType.Left, "Book", "ID", "Student", "BookID"))
                .Select("Student.ID, Student.Name, Class.Name, Book.Name, Student.DOB");
    

Note: As per before information all jTable has same method of dTable. so you can do any operation with table.

Support

Once again, As I said at the beginning, I'd be glad to help you if you have any questions relating to this code. I'll do my best to assist. If you have a more general question relating to the code on CodeCanyon, you might contact me at here. Thanks so much!.

For new features:

Though we will never discourage users from developing solutions that solve their needs, the goals of the SQL Helper are very focused. If you are looking to get new features merged back into the SQL Helper DLL, we highly encourage you to contact me at ajmerainfo@gmail.com or write comment on my CodeCanyon this product page.

Thanks.