|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
What is this?DBHelper is a small tool that will generate either a source file or a compiled assembly for selected stored procedures on your SQL server. It uses the Basically, this is an all-in-one tool for wrapping a SQL database. Great for existing databases, and for rapidly changing databases. E.g. changes gets made to stored procedure's parameters or the output of stored procedures. No problem for DBHelper, just a few clicks and you a have all the methods remapped/ NOTE: New information (version 1.5+)As of version 1.4, the package comes as a tool rather than a library. Please select the SQL provider (no others will work and I have NO plans to support it). If you tick Create, it will create a corresponding method, and Also note VS.NET is NO longer required for typed Version 1.6 includes plenty code optimization. Also, typed datasets now get created based on return values. The is no more option to select which ones you want. I have tested it successfully on the MASTER database. Why?Some people might ask "Why?". The answer is sweet. Take the following for example: Every time you even want to execute a simple stored procedure you need something like the following: SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandText = "ChangeEmail";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@id", SqlDbType.BigInt).Value = id_param;
cmd.Parameters.Add("@oldemail", SqlDbType.VarChar).Value = oldemail_param;
cmd.Parameters.Add("@newemail", SqlDbType.VarChar).Value = newemail_param;
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
Now that's only 3 parameters, how about some nasty UPDATE: I have now updated the library to return a public static DataTable ChangeEmail(SqlConnection connection
DataTable table, long id_param,
string oldemail_param, string newemail_param)
The code from the former example is automatically inserted into a class of choice. Now that looks a lot better, and will probably save you countless hours. How does it work?These methods are a bit redundant as of version 1.4 as it run as a tool rather than a library. Firstly your database will be queried for stored procedures. After that we get the name and type of the parameters for each procedure. With the help of Constructor
Properties
Methods
NotesI use a very, very simple mapping from For the test app to work you will need to change the Free plugKristopher Johnson - Typed Collection Class Generator for creating all the collections and dictionaries in DBHelper (although the CodeDom code was not looked at). ConclusionThis was really my first successful use of CodeDom and it seems really powerful, especially if you use it correctly as output to any language should be possible. As usual, bugs, problems, praise, suggestions, gifts can be added below. UPDATE: I have created support for VB.NET code as well. Cheers :)
|
||||||||||||||||||||||