views:

33

answers:

2

I have SQL Server stored procedures which have several inputs. I want to save time from manually creating C# ADO.NET sqlParameter arrays as in

sqlParameter[] sqlParameters = 
                { new SqlParameter("customerID", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, string.Empty, DataRowVersion.Default, custID) .......

Any code generator which can this and a template which can do this? If you mention a code generator, please mention which template. Like which one for CodeSmith.

A: 

If you don't have a large number of stored procedures, you can write a macro in Visual Studio to generate the code (see this for example). Actually, depending on how you write the macro, it can handle a large number too.

If you have no requirement for a manually crafted DAL, then you probably should consider using an ORM (Entity Framework, LINQ to SQL .. etc) which will generate the code for you.

Waleed Eissa
I need something which works out of the box or needs little rework. What macro which can go to a stored procedure and create such statements? It seems it's easiier to write c# code to do that. Another ORM is not an option. I specifically mentioned that in my comment.
Tony_Henrich
Sorry for that. It's because of the way I work (I write all sprocs by hand and keep them in a text file which I use to generate the related DAL methods later). But of course this might not be convenient to everyone.
Waleed Eissa
A: 

Why don't you try CodeHelper is a Addin for VS (2005,2008,2010) and it has a Code generator for Store Procedureces, INSERT,UPDATE,DELETE Methods (from tables), Entities, etc

you can see it on: http://visualstudiogallery.msdn.microsoft.com/en-us/c736dedf-bbed-454a-8073-89993ca46902

rafaelsr
The stored procs are already created. I don't want to create stored procs.
Tony_Henrich
then you can use Method Creation if you have a SP for Select or insert or Update you can create a Method for Sel/INS/UPD and CodeHelper will create your paramas and everything, I use a lot that functionality, after that you can go to created method and make changes to it, but almost everything will be created automatically
rafaelsr