Shall I use DAAB AddInParameter with @ or without @

Topics: Data Access Application Block
Mar 11, 2009 at 1:11 AM

What is the right way to pass parameters to store proc for parameters name?
Should the parameter names have @ in front or not?

DbCommand dbCommand = db.GetStoredProcCommand( "store proc name" );

Using db.AddInParameter( dbCommand, "date_char", DbType.String, dateyyyyMMd ) does not work
while
db.AddInParameter( dbCommand, "@date_char", DbType.String, dateyyyyMMd ) does work.

Thanks

Mar 11, 2009 at 3:10 AM
If your db instance is of type SqlDatabase, it automatically adds the @ character to the parameter name if you didn't do so.  The base Database class default implementation of the BuildParameterName method just returns the name you passed while in the SqlDatabase class, it checks first if the name you passed starts with the @ character and if not, adds it.  The Oracle database class uses the default implementation.  If you created your own database implementation, override the BuildParameterName method.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Mar 11, 2009 at 7:06 PM
Glad to hear that it work both ways. This is my own sybase implementation using DB2 sybase. Scratch the db2 and model it after sqlDatabase since sybase and sql use t-sql and closer to each other. Now it works both ways.

Thanks