TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ron
NA
44
64.4k
Cleaning up an ADO connection.
Aug 19 2010 3:50 PM
I have written a class that accesses data from an SQL database. Here is the class:
public
DataSet
GetData(
int
nCol)
string
cSQLSelect =
@"SELECT * FROM table"
;
SqlConnection
conDB =
new
SqlConnection
(GetConnString());
SqlDataAdapter
da =
new
SqlDataAdapter
(cSQLSelect, conDB);
DataSet
ds =
new
DataSet
();
da.Fill(ds,
"table"
);
return
ds;
In my windows form I'm calling this class and binding the first column to a textbox. Here is the code:
private
void
button1_Click(
object
sender,
EventArgs
e)
{
DataSet
ds = class.GetData(11007);
textBox1.DataBindings.Add(
"text"
, ds,
"table.col1"
);
}
This code works, the data appears in the textbox just as I expected. But here is my concern: Am I leaving the connection open by using this methodology? Apparently the data adapter does not require a call to the open method. So does the connection close automatically?
I'm new to C# programming, and I don't know the best strategy to handle this situation.
Reply
Answers (
4
)
Need a WebBrowser control to run in Protected Mode
ado.net