|
1 |
| -Option Explicit |
2 |
| -Option Strict |
3 |
| - |
4 |
| -Imports System.Data |
| 1 | +Option Explicit On |
| 2 | +Option Strict On |
5 | 3 | ' <Snippet1>
|
6 | 4 | Imports System.Data.Odbc
|
7 | 5 |
|
8 | 6 | Module Module1
|
9 |
| - Sub Main() |
10 |
| - Dim builder As New OdbcConnectionStringBuilder() |
11 |
| - builder.Driver = "Microsoft Access Driver (*.mdb)" |
12 |
| - |
13 |
| - ' Call the Add method to explicitly add key/value |
14 |
| - ' pairs to the internal collection. |
15 |
| - builder.Add("Dbq", "C:\info.mdb") |
16 |
| - |
17 |
| - Console.WriteLine(builder.ConnectionString) |
18 |
| - Console.WriteLine() |
19 |
| - |
20 |
| - ' Clear current values and reset known keys to their |
21 |
| - ' default values. |
22 |
| - builder.Clear() |
23 |
| - |
24 |
| - ' Pass the OdbcConnectionStringBuilder an existing |
25 |
| - ' connection string, and you can retrieve and |
26 |
| - ' modify any of the elements. |
27 |
| - builder.ConnectionString = _ |
28 |
| - "driver={IBM DB2 ODBC DRIVER};Database=SampleDB;" & _ |
29 |
| - "hostname=SampleServerName;port=SamplePortNum;" & _ |
30 |
| - "protocol=TCPIP" |
31 |
| - |
32 |
| - Console.WriteLine("protocol = " & builder("protocol").ToString()) |
33 |
| - Console.WriteLine() |
34 |
| - |
35 |
| - ' Call the Remove method to remove items from |
36 |
| - ' the collection of key/value pairs. |
37 |
| - builder.Remove("port") |
38 |
| - |
39 |
| - ' Note that calling Remove on a nonexistent item does not |
40 |
| - ' throw an exception. |
41 |
| - builder.Remove("BadItem") |
42 |
| - Console.WriteLine(builder.ConnectionString) |
43 |
| - Console.WriteLine() |
44 |
| - |
45 |
| - ' The Item property is the default for the class, |
46 |
| - ' and setting the Item property adds the value, if |
47 |
| - ' necessary. |
48 |
| - builder("NewKey") = "newValue" |
49 |
| - Console.WriteLine(builder.ConnectionString) |
50 |
| - |
51 |
| - Console.WriteLine("Press Enter to finish.") |
52 |
| - Console.ReadLine() |
53 |
| - End Sub |
| 7 | + Sub Main() |
| 8 | + Dim builder As New OdbcConnectionStringBuilder With { |
| 9 | + .Driver = "Microsoft Access Driver (*.mdb)" |
| 10 | + } |
| 11 | + |
| 12 | + ' Call the Add method to explicitly add key/value |
| 13 | + ' pairs to the internal collection. |
| 14 | + builder.Add("Dbq", "C:\info.mdb") |
| 15 | + |
| 16 | + Console.WriteLine(builder.ConnectionString) |
| 17 | + Console.WriteLine() |
| 18 | + |
| 19 | + ' Clear current values and reset known keys to their |
| 20 | + ' default values. |
| 21 | + builder.Clear() |
| 22 | + |
| 23 | + ' Pass the OdbcConnectionStringBuilder an existing |
| 24 | + ' connection string, and you can retrieve and |
| 25 | + ' modify any of the elements. |
| 26 | + builder.ConnectionString = |
| 27 | + "driver={IBM DB2 ODBC DRIVER};Database=SampleDB;" & |
| 28 | + "hostname=SampleServerName;port=SamplePortNum;" & |
| 29 | + "protocol=TCPIP" |
| 30 | + |
| 31 | + Console.WriteLine("protocol = " & builder("protocol").ToString()) |
| 32 | + Console.WriteLine() |
| 33 | + |
| 34 | + ' Call the Remove method to remove items from |
| 35 | + ' the collection of key/value pairs. |
| 36 | + builder.Remove("port") |
| 37 | + |
| 38 | + ' Note that calling Remove on a nonexistent item does not |
| 39 | + ' throw an exception. |
| 40 | + builder.Remove("BadItem") |
| 41 | + Console.WriteLine(builder.ConnectionString) |
| 42 | + Console.WriteLine() |
| 43 | + |
| 44 | + ' The Item property is the default for the class, |
| 45 | + ' and setting the Item property adds the value, if |
| 46 | + ' necessary. |
| 47 | + builder("NewKey") = "newValue" |
| 48 | + Console.WriteLine(builder.ConnectionString) |
| 49 | + |
| 50 | + Console.WriteLine("Press Enter to finish.") |
| 51 | + Console.ReadLine() |
| 52 | + End Sub |
54 | 53 | End Module
|
55 | 54 | ' </Snippet1>
|
56 | 55 |
|
0 commit comments