Skip to content

Commit a2c7a33

Browse files
committed
fix up VB snippets to match C# snippets
1 parent 4042826 commit a2c7a33

File tree

12 files changed

+203
-226
lines changed

12 files changed

+203
-226
lines changed

snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlCommand.ExecuteReader Example/VB/Project.vbproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
1111

1212
</Project>

snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlCommand.ExecuteReader2/VB/Project.vbproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
1111

1212
</Project>

snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlCommand.SqlCommand2 Example/VB/Project.vbproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
1111

1212
</Project>

snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction Example/VB/Project.vbproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
1111

12-
</Project>
12+
</Project>

snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction2 Example/VB/Project.vbproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
1111

12-
</Project>
12+
</Project>

snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlConnection.BeginTransaction3 Example/VB/Project.vbproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
1010
</ItemGroup>
1111

12-
</Project>
12+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
1-
Option Explicit
2-
Option Strict
3-
4-
Imports System.Data
5-
' <Snippet1>
1+
Option Explicit On
2+
Option Strict On
63
Imports System.Data.SqlClient
7-
4+
85
Module Module1
9-
Sub Main()
10-
Try
11-
Dim connectString As String = _
12-
"Data Source=(local);User ID=ab;Password=a1Pass@@11;" & _
13-
"Initial Catalog=AdventureWorks"
14-
15-
Dim builder As New SqlConnectionStringBuilder(connectString)
16-
Console.WriteLine("Original: " & builder.ConnectionString)
17-
18-
' Use the Remove method
19-
' in order to reset the user ID and password back to their
20-
' default (empty string) values.
21-
builder.Remove("User ID")
22-
builder.Remove("Password")
23-
24-
' Turn on integrated security:
25-
builder.IntegratedSecurity = True
26-
27-
Console.WriteLine("Modified: " & builder.ConnectionString)
28-
29-
Using connection As New SqlConnection(builder.ConnectionString)
30-
connection.Open()
31-
' Now use the open connection.
32-
Console.WriteLine("Database = " & connection.Database)
33-
End Using
34-
35-
Catch ex As Exception
36-
Console.WriteLine(ex.Message)
37-
End Try
38-
39-
Console.WriteLine("Press any key to finish.")
40-
Console.ReadLine()
41-
End Sub
6+
Sub Main()
7+
Try
8+
' <Snippet1>
9+
Dim connectString As String =
10+
"Data Source=(local);User ID=ab;Password=a1Pass@@11;" &
11+
"Initial Catalog=AdventureWorks"
12+
13+
Dim builder As New SqlConnectionStringBuilder(connectString)
14+
Console.WriteLine("Original: " & builder.ConnectionString)
15+
16+
' Remove the user ID and password.
17+
builder.Remove("User ID")
18+
builder.Remove("Password")
19+
20+
' Turn on integrated security:
21+
builder.IntegratedSecurity = True
22+
23+
Console.WriteLine("Modified: " & builder.ConnectionString)
24+
25+
Catch ex As Exception
26+
Console.WriteLine(ex.Message)
27+
End Try
28+
29+
' This code produces the following output:
30+
' Original: Data Source=(local);Initial Catalog=AdventureWorks;User ID=ab;Password=a1Pass@@11
31+
' Modified: Data Source = (local);Initial Catalog=AdventureWorks;Integrated Security=True
32+
' </Snippet1>
33+
End Sub
4234
End Module
43-
' </Snippet1>
4435

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net4.8</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
1-
Option Explicit
2-
Option Strict
1+
Option Explicit On
2+
Option Strict On
33

4-
54
' <Snippet1>
65
Imports System.Data.SqlClient
76

87
Module Module1
98
Sub Main()
109
' Create a new SqlConnectionStringBuilder and
1110
' initialize it with a few name/value pairs:
12-
Dim builder As New SqlConnectionStringBuilder(GetConnectionString())
11+
Dim builder As New SqlConnectionStringBuilder(
12+
"Server=(local);Integrated Security=true;" &
13+
"Initial Catalog=AdventureWorks"
14+
)
1315

1416
' The input connection string used the
1517
' Server key, but the new connection string uses
1618
' the well-known Data Source key instead.
17-
Console.WriteLine(builder.ConnectionString)
19+
Console.WriteLine("Original connection string: " + builder.ConnectionString)
1820

19-
' Pass the SqlConnectionStringBuilder an existing
20-
' connection string, and you can retrieve and
21-
' modify any of the elements.
22-
builder.ConnectionString = _
23-
"server=(local);user id=ab;" & _
24-
"password=a!Pass113;initial catalog=AdventureWorks"
2521
' Now that the connection string has been parsed,
2622
' you can work with individual items.
27-
Console.WriteLine(builder.Password)
28-
builder.Password = "new@1Password"
23+
Console.WriteLine("Initial catalog: " + builder.InitialCatalog)
24+
builder.InitialCatalog = "Northwind"
2925
builder.AsynchronousProcessing = True
3026

3127
' You can refer to connection keys using strings,
@@ -40,18 +36,8 @@ Module Module1
4036
' and setting the Item property adds the value to the
4137
' dictionary, if necessary.
4238
builder.Item("Trusted_Connection") = True
43-
Console.WriteLine(builder.ConnectionString)
44-
45-
Console.WriteLine("Press Enter to finish.")
46-
Console.ReadLine()
39+
Console.WriteLine("Modified connection string: " + builder.ConnectionString)
4740
End Sub
48-
49-
Private Function GetConnectionString() As String
50-
' To avoid storing the connection string in your code,
51-
' you can retrieve it from a configuration file.
52-
Return "Server=(local);Integrated Security=SSPI;" & _
53-
"Initial Catalog=AdventureWorks"
54-
End Function
5541
End Module
5642
' </Snippet1>
5743

0 commit comments

Comments
 (0)