Sometime ago I posted a Query which can generate the
parameters for the C# code Generate Parameters using T-SQL.
Now, I have converted that T-SQL to a simple Stored Procedure which you
can use in your database.
Here is the STORED PROCEDURE:
/*
Author: Mohammad Azam
Email: azamsharp@gmail.com
Description: This stored procedure is used to
generate parameters for the C# code.
DateCreated: 01-05-2006
DateModified: 01-05-2006
Usage: Create the stored procedure in the database
you want to use and then use the EXEC [procedure name] 'Table Name'
*/
CREATE PROCEDURE [usp_GenerateParams]
@table_name nvarchar(20)
AS
-- declare the variables
DECLARE @column_name nvarchar(20)
DECLARE @commandObjectName varchar(20)
DECLARE @SQLString nvarchar(4000)
DECLARE @GenCode nvarchar(4000)
SET @GenCode = ''
SET @commandObjectName = 'myCommand'
Select @GenCode = @GenCode + CHAR(13) +
'myCommand.Parameters.AddWithValue("@'+column_name+'",'+column_name+')'
from information_schema.columns where table_name = @table_name
Print @GenCode
GO
powered by IMHO 1.3