index > Visual C# General > A Better Way to ReUse Sql Objects

A Better Way to ReUse Sql Objects

Using C# in a windows form, the code snippet below works, but looks very ineffecient to me. I created 2 pairs of objects to do 2 separate but similar tasks (conn & conn1, cmd & cmd1 etc).

It seems like I should be able to reuse conn, and perhaps cmd, but I am not sure what I need to release, reset, etc. I have been running into a host of errors.

What would be an effecient way to reorganize this code?

Many thanks,
Mike Thomas

// set up stored proc
M Thomas
Have both commands use the same connection object. Unless you need to read data from two commands concurrently (i.e., read some data from one command, then the other, then from the first again), you only need one connection. Connections are pooled anyway, so having more than one isn't all that expensive. You can reuse command objects too, but its usually not worth the trouble.
Nimrand
reply 2

You can use google to search for other answers

 

More Articles

• Label Justify text
• Windows service connecting to UNC path on another domain.
• DataTable does not accept field changes
• Tpshimo Services Offline!
• sending multiply POST commands simultaneous through Internet?
• Identifying Italic Text
• serialport- stopbits.none error
• How to create local instance of the remote object
• ClickOnce Publishing Application to web site
• Start Application inbedded on a form
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Please give an advice in the following c
• Word COM base interface
• Converting String to URL type
• Removing the double quotes from a CSV fi
• firing onfocus or onkeydown events of an
• Combinations of matrix
• How to send an object by TCP?
• How to know whether an Excel file is ope
• auto ID in xml
• Can datagridview host a user control (no
• Chinese words in DataGrid
• An error about reference a COM component
• Beginning C# / .NET Questions (re: Time
• Unrecognized configuration section 'conn
• how to synchronize a hash table

Hot Articles

• How to: create an enumeration user setting
• Can C# do this??
• Last day of the month...using TimeDate
• easy way to determine if string is one l
• Outlook plugin with express beta 2
• Default Value for Datagridview Combobox
• Trimming a path
• [off topic] How to set cookies on when I
• how to display Expand Collapse rows in d
• Can Generics solve problem of cross refe
• Mouse leave event, on child controls
• Enum Components
• Using an OLE object without having the TLB
• USB Device
• Capturing mouse button (Middle one)

Recommend Articles

• GetType from instance that has a null va
• Problem with Virtual folder
• Problem using EntLib DAAB for .NET 2.0
• combo box display tables
• Dynamic assignment of Data Objects
• .Net2 Webbrowser control: detecting DOM
• Interfaces
• really stuck on a game idea...need help
• Move Directory Across Volumes
• How can i extract labels based on a cert
• hidden text in richtextbox
• Cross-string operation not valid...
• Running programs from a windows service
• Syntax Error in Update Statement
• How this code work(C# 2.0)? It shouldn't!