Idisposable interface and the using statement in SQL

I'm having problem finding a good Vb.net example that shows how to dispose a sql connection via the idisposable interface. Also with the 'using' statement. Does anyone have a good small example using both of these keywords?
7of9121098Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DarrenDConnect With a Mentor Commented:
Here is one link for the first part of you question.

http://blog.devstone.com/aaron/archive/2004/06/03/184.aspx
0
 
DarrenDCommented:
Hi,

As far as I know you cannot use the 'using' statement in VB.NET only C#

Darren
0
 
DarrenDCommented:
Ah...I was only thinking about .NET 1.1


I amwrong in VB.NET 2.0 you can use Using

http://pluralsight.com/blogs/fritz/archive/2005/04/28/7834.aspx
0
 
DarrenDCommented:
Here is a way to get Using working in VB.NET 1.1


Dim conn As SqlConnection = New SqlConnection(dsn)
Try
Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM Employees", conn)
Try
conn.Open()
rdr = cmd.ExecuteReader()
While rdr.Read()
Console.WriteLine(rdr(0))
End While
Finally
If Not cmd is Nothing Then
cmd.Dispose()
End If
End Try
Finally
If Not conn is Nothing Then
conn.Dispose()
End If
End Try


Hope this Helps

Darren
0
All Courses

From novice to tech pro — start learning today.