473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

sqlcommand question

I got a silly question about Sqlcommand . In my form, there are 5 methods
which use the same sqlcommand to execute reader.
I had create and dispose for each sqlcommand in every method. Some said
that I can only delcare one sqlcommand and re-use it in every
method and no need to dispose until form closed. I am wonder which approach
is correct.
public class myform
Dim cmdSearch As New SqlClient.SqlCommand

method 1
method 2
method 3

my approach
public class myform
method1
Dim cmdSearch As New SqlClient.SqlCommand
........
cmdSearch.dispose
method2
Dim cmdSearch As New SqlClient.SqlCommand
........
cmdSearch.dispose
method3
Dim cmdSearch As New SqlClient.SqlCommand
........
cmdSearch.dispose
............


Jan 22 '06 #1
0 1143

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dylan Phillips | last post by:
A strang error is occurring when I run the following code: SqlConnection c = new SqlConnection(); c.ConnectionString = "Initial Catalog=Northwind;user id=sa;password=kat1ie;Data Source=server";...
10
by: Henrik Dahl | last post by:
Hello! After I've finished using an instance of the SqlCommand class, should I then invoke Dispose() on the instance. I suppose so, as there is a Dispose method, but what does it actually...
6
by: BuddyWork | last post by:
Does anyone know if there are any articles explaining how I could debug into SqlCommand.ExecuteReader so I can see why I am getting a particular error. thanks
1
by: Tom | last post by:
Hello guys Please have a look on following paragraph from ".NET Data Access Architecture Guide". ''''''''''' Although you can repeatedly use the same SqlCommand object to execute the same...
3
by: Jason Huang | last post by:
Hi, In C#.Net, can we have more than one SqlCommand in a SqlConnection? And in one SqlCommand, can we have more than one SqlDataReader in a SqlCommand? In what situation should I use...
20
by: John Bailo | last post by:
I have a c# program that loops through a table on a DB2 database. On each iteration it assigns data to values in the SqlParameter collection. The command text is an INSERT statement to a Sql...
10
by: John Bailo | last post by:
I want to pass a SqlCommand object as a input parameter to a method. I want to pass the SqlCommand "by value" so that any updates to the original object are *not* reflected in the object within...
1
by: job | last post by:
how is it possible to serialize/de-serialize a SqlCommand?
2
by: fniles | last post by:
I am using .Net 2003 and querying a SQL Server 2000 database. I read the database in a loop, but on every iteration I set the SQLCommand to new, set it, execute it, dispose and set it to nothing....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.