473,396 Members | 1,982 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,396 software developers and data experts.

VB.NET Equiv of...

Hi All!

Does VB.NET have an equivelent of the following C# statement (the using
part):

using (SqlConnection connection = new SqlConnection(connStr))
{
}
TIA
BW

--
-- Formerly brianw@gold_death_2_spam_rush.com
Nov 21 '05 #1
7 1119
The "using" statement will be introduced to the VB.Net language in the 2.0
release. For now you can just use a try/finally/dispose pattern, which is
essentially what the using statement gets blown out into.

--
Tim Wilson
..Net Compact Framework MVP

"Brian W" <no****@yourbusiness.com> wrote in message
news:Ov**************@TK2MSFTNGP14.phx.gbl...
Hi All!

Does VB.NET have an equivelent of the following C# statement (the using
part):

using (SqlConnection connection = new SqlConnection(connStr))
{
}
TIA
BW

--
-- Formerly brianw@gold_death_2_spam_rush.com

Nov 21 '05 #2
> Does VB.NET have an equivelent of the following C# statement (the
using part):

using (SqlConnection connection = new SqlConnection(connStr))
{
}


I believe this would translate as:

Dim connection As New SqlConnection(connStr)
With connection
[...]
End With

Hope that helps,

--

(O)enone
Nov 21 '05 #3
Tim Wilson wrote:
The "using" statement will be introduced to the VB.Net language in
the 2.0 release. For now you can just use a try/finally/dispose
pattern, which is essentially what the using statement gets blown out
into.


Ah, ok, ignore my response then. :)

--

(O)enone
Nov 21 '05 #4
"Oenone" <oe****@nowhere.com> schrieb:
Does VB.NET have an equivelent of the following C# statement (the
using part):

using (SqlConnection connection = new SqlConnection(connStr))
{
}


I believe this would translate as:

Dim connection As New SqlConnection(connStr)
With connection
[...]
End With


No, it won't ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #5
"Brian W" <no****@yourbusiness.com> schrieb:
Does VB.NET have an equivelent of the following C# statement (the using
part):

using (SqlConnection connection = new SqlConnection(connStr))
{
}


VB.NET 2002/2003 don't provide such a construct, but VB 2005 will include
'Using' too. 'using' can be replaced by this "pattern":

\\\
Dim Connection As SqlConnection
Try
Connection = New SqlConnection()
Connection.Open()

' Use the connection here.
Finally
If Not Connection Is Nothing Then
Connection.Dispose()
End If
End Try
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #6

BUZZZZZZZZ! nope!

A VB.NET With block only allows the developer to not specify the object
name when calling properties, methods etc. As in:

With myObj
.DoSomething()
.DoSomethingElse
aString = .ToString()
End With

The using statement, as representedin my example, means the compiler
will automatically call Dispose() when the assigned instance goes out
of scope.

So, the object assigned in the using statement must implement interface
IDispose.

For the C# folks, I realize the using statement is a C# construct;
however, I am just trying to find if there is an equivelent construct
in VB.NET.
Oenone wrote:
Does VB.NET have an equivelent of the following C# statement (the
using part):

using (SqlConnection connection = new SqlConnection(connStr))
{
}


I believe this would translate as:

Dim connection As New SqlConnection(connStr)
With connection
[...]
End With

Hope that helps,

Nov 21 '05 #7
Herfried,
No, it won't ;-).

Read the tread, that is what Oenone said in the answer to Tim Wilson who
gave the right answer.

Cor
Nov 21 '05 #8

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

Similar topics

0
by: Donald Gordon | last post by:
Hi I'm trying to retrieve an HTML document in UTF-8 format using LWP, but have hit a snag: the document redefines the Content-type: header from "text/html" to "text/html; charset=UTF-8" using a...
1
by: Troy | last post by:
Hello- I have a need to allow a user to reload a page on a chosen interval (selected from a select box) or to chose not to reload the page at all (default). I would like to do this in...
8
by: Nige | last post by:
I've got an old web site that comes up before its replacement in Google listings. I've read the document on Google about sending a "301" code from the server:...
3
by: Marcia Gulesian | last post by:
Is there a way to replace the URL value below, on the fly? <META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://www.some.org/some.html">
10
by: Udi Zisser | last post by:
Hello, any idea why this does not work? or how do i get this thing to work? <BASE HREF="http://localhost/thedude/"> <META HTTP-EQUIV="Refresh" CONTENT="0; URL=redirect.html"> I'm adding...
10
by: Newry | last post by:
Hi, If you have both this HTTP header: Content-Type: text/html; charset=ISO-8859-1 and this HTML element in the <head>: <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
0
dmjpro
by: dmjpro | last post by:
i use a code ..... in my html page like .... <meta http-equiv = 'Window-target' content = '_blank'> what will be the effect .... what i know about the http-equiv = 'Window-target' ......
2
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hello, I have an ASP.NET 2.0 application with the following meta tag to refresh the page after a minute. <meta http-equiv="Refresh" content="60; URL=Default.aspx" /> I need to be able to...
2
by: runway27 | last post by:
i have a registration page which is a self submitting form <form action="<?php echo $_SERVER; ?>" method="POST" id="test2" name="registrationform"> where in a user fill a form, after the data...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.