Solved

C# sql proper declaration

Posted on 2007-03-18
2
178 Views
Last Modified: 2010-04-16
Is it better to do this in a form:
form beginning:
 SqlCommand cmd;

then throughout the code
cmd = new sqlcommand("select * from table", Connection);

or should it be like this
Form Beginning
SqlCommand cmd = new sqlcommand();

then throughout the code
cmd.connection = connection;
cmd.commandtext = "select * from table";


0
Comment
Question by:bman9111
2 Comments
 
LVL 15

Accepted Solution

by:
stanscott2 earned 500 total points
ID: 18745870
Since they're functionally equivalent, I always prefer the shorter one -- doing it in one line, rather than two.  EIther is correct, though.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18746393
it depends. if you create a command object that is used several times/often, define it in the global class, and use it all over the project.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question