[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1212
  • Last Modified:

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?
0
JRockFL
Asked:
JRockFL
2 Solutions
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now