SQLDataReader Code Generator
Here is a SqlDataReader Code Generator that can save you a hours of programming time. The name of the tool is Ideal Tools Organizer, and it contains a very powerful built in tool called SQL to Grid. You can download the SqlDataReader Code Generator tool now by clicking on Ideal Tools Organizer.
SQLDataReader Code Generator: Overview of SQL to Grid
The purpose of the SQL To Grid Tool is to allow one to quickly generate the VB.NET or C-Sharp code needed to get data from a sql server query, or stored procedure, and display the results in a gridview.
The main task that you have to do in order to use SQL to Grid is to write a sql query or stored procedure. If you find it difficult to write a sql query, you may want to use SSMS to help you. In SSMS, if you right click while in the query window, you can select “Design in Query Editor” in order to get a very nice visual designer.
SQL To Grid uses sqldatareader to process each row. Each row is added to a datatable that is then bound to the gridview.
If you only want to generate code to get data out of a sql server database and do not care about going to a gridview, you can just delete the code that adds rows to a data table and binds the table to a gridview. This will leave you with a nice little loop that uses sqldatareader to read each row. The loop will get each column in the select statement and put it into field that you can easily manipulate.
SqlDataReader Code Generator: Benefits
1. Detail Code Eliminates the Need to Use FindControl
The advantage of using the SQL To Grid tool over using ADO.NET sqldatasource is that SQL To Grid generates all the detail code to make it easy for you to modify. SqlDataSource is a kind of fire-hose approach, but it is very difficult to find where to modify each field in the datarowbound event. SQL To Grid makes it where you do not have to use FindControl to try to find the column in each row.
2. ItemTemplates Make It Easy to Modify How Gridview Displays Information
Another advantage of SQL To Grid is that it generates item templates for each of the fields in the gridview so that you can easily modify how the information is diplayed in the gridview without having to manually create your own item templates.
SqlDataReader Code Generator: Inputs
Sql To Grid takes three types of inputs:
1. Connection Strings
Connection String allows you to specify the database, etc. to use. Do not put quotes around the connection string.
2. Sql Statement or Stored Procedure
The sql statement can involve multiple tables and be just about as complicated as you want to be.
3. Parameters
You have up to five parameters. If you are using a sql statement, the computer will find the parameters in your statement and prefill the parameter names for you. You need to include the @ in front of each parameter name.
SqlDataReader Code Generator: Outputs
Sql To Grid generates two types of output:
1. Code-Behind
The code-behind consists of some commented out using or import statements and a subroutine called ReadSql(). You will need to add the call to ReadSql in the load event for your page if you want to populate the gridview on page load.
2. ASPX Code for Gridview with ItemTemplates
The ItemTemplates make it easy for you to modify how the data is displayed in the gridview.