|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 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. -- Show quoteHide quoteTim Wilson ..Net Compact Framework MVP "Brian W" <non***@yourbusiness.com> wrote in message news:OvkIGt3PFHA.2136@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 Tim Wilson wrote:
> The "using" statement will be introduced to the VB.Net language in Ah, ok, ignore my response then. :)> 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. -- (O)enone > Does VB.NET have an equivelent of the following C# statement (the I believe this would translate as:> using part): > > using (SqlConnection connection = new SqlConnection(connStr)) > { > } Dim connection As New SqlConnection(connStr) With connection [...] End With Hope that helps, -- (O)enone
Show quote
Hide quote
"Oenone" <oen***@nowhere.com> schrieb: No, it won't ;-).>> 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 -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> 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 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: Show quoteHide quote > > 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, "Brian W" <non***@yourbusiness.com> schrieb: VB.NET 2002/2003 don't provide such a construct, but VB 2005 will include > Does VB.NET have an equivelent of the following C# statement (the using > part): > > using (SqlConnection connection = new SqlConnection(connStr)) > { > } '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/>
ASCII lookup table
Datagrid resizing rows on sort - not wanted AxWebBrowser1 and code behind redirecting Datagrid - shown vertically instead of horizontally? Reading from a ini-file and run a program How do I measure the time it takes to copy a file? Easy one about web forms Assigning a Null to Datetime Variable or Object form location Registering my program as default for my file extension |
|||||||||||||||||||||||