473,327 Members | 1,952 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,327 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 17 '05 #1
7 1229
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 17 '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 17 '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 17 '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 17 '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 17 '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 17 '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 17 '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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.