SqlCommand.Parameters.Add()

SqlCommand.Parameters.Add() has 5 overloads.
Which one should typically be used, and why? Should you specify DbType? What is this for?
LVL 8
JRockFLAsked:
Who is Participating?
 
JimBrandleyCommented:
I use this one:
Parameters.Add(object);
This way, the callers of the DB Access class I have can create a list of parameters appropriate to the current request. They pass the parameter list in with the SQL or SP name.

SqlDbType tells and code that refers to the parameter how to interpret the content of the Value member.

Jim
0
 
edwardqCommented:
I use sqlparameter one.   I have a class that contains all the connections to the database. I send to the class a ArrayList of Sqlparameters. In the class member I loop though the ArrayList and then add each one to the ot the sqlcommand.

ex.  ArrayList mysqlpara = new ArrayList();
mysqlpara.add(new sqlclient.sqlparameter("@name",txtName.Text);

The DbType is for it you are controling the data type to the database. I havint used it yet. I beleve you get a error on code side if you put the wrong type in, instead of the database reportiing it back.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.