Skip to content

Commit 5037ff8

Browse files
authored
Reorganize ADO.NET VB snippets (#11534)
1 parent 03a95c5 commit 5037ff8

File tree

835 files changed

+886
-1075
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

835 files changed

+886
-1075
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
Imports System.Xml
2-
Imports System.Data
1+
Imports System.Data
32
Imports System.Data.SqlClient
4-
Imports System.Data.Common
5-
Imports System.Windows.Forms
63

74

85

9-
Public Class Form1
10-
Inherits Form
11-
Protected DataSet1 As DataSet
12-
Protected dataGrid1 As DataGrid
13-
14-
15-
6+
Public Class Class1
7+
8+
169
' <Snippet1>
1710
Public Sub CreateCommand()
1811
Dim queryString As String = "SELECT * FROM Categories ORDER BY CategoryID"
1912
Dim command As New SqlCommand(queryString)
2013
command.CommandTimeout = 15
2114
command.CommandType = CommandType.Text
22-
End Sub
15+
End Sub
2316
' </Snippet1>
2417
End Class
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
Option Explicit On
22
Option Strict On
3-
4-
Imports System.Data
53
' <Snippet1>
64
Imports System.Data.SqlClient
5+
Imports System.Windows.Forms
76

87
Public Class Form1
98
' Add this code to the form's class:
@@ -30,7 +29,7 @@ Public Class Form1
3029
' If you have not included "Asynchronous Processing=true" in the
3130
' connection string, the command is not able
3231
' to execute asynchronously.
33-
Return "Data Source=(local);Integrated Security=true;" & _
32+
Return "Data Source=(local);Integrated Security=true;" &
3433
"Initial Catalog=AdventureWorks; Asynchronous Processing=true"
3534
End Function
3635

@@ -43,21 +42,21 @@ Public Class Form1
4342
DisplayStatus("Ready")
4443
End Sub
4544

46-
Private Sub Form1_FormClosing(ByVal sender As Object, _
47-
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
45+
Private Sub Form1_FormClosing(ByVal sender As Object,
46+
ByVal e As FormClosingEventArgs) _
4847
Handles Me.FormClosing
4948
If isExecuting Then
50-
MessageBox.Show(Me, "Cannot close the form until " & _
49+
MessageBox.Show(Me, "Cannot close the form until " &
5150
"the pending asynchronous command has completed. Please wait...")
5251
e.Cancel = True
5352
End If
5453
End Sub
5554

56-
Private Sub Button1_Click(ByVal sender As System.Object, _
55+
Private Sub Button1_Click(ByVal sender As System.Object,
5756
ByVal e As System.EventArgs) Handles Button1.Click
5857
If isExecuting Then
59-
MessageBox.Show(Me, _
60-
"Already executing. Please wait until the current query " & _
58+
MessageBox.Show(Me,
59+
"Already executing. Please wait until the current query " &
6160
"has completed.")
6261
Else
6362
Dim command As SqlCommand
@@ -69,11 +68,11 @@ Public Class Form1
6968
' a few seconds before working with the data.
7069
' This command does not do much, but that's the point--
7170
' it does not change your data, in the long run.
72-
Dim commandText As String = _
73-
"WAITFOR DELAY '0:0:05';" & _
74-
"UPDATE Production.Product SET ReorderPoint = ReorderPoint + 1 " & _
75-
"WHERE ReorderPoint Is Not Null;" & _
76-
"UPDATE Production.Product SET ReorderPoint = ReorderPoint - 1 " & _
71+
Dim commandText As String =
72+
"WAITFOR DELAY '0:0:05';" &
73+
"UPDATE Production.Product SET ReorderPoint = ReorderPoint + 1 " &
74+
"WHERE ReorderPoint Is Not Null;" &
75+
"UPDATE Production.Product SET ReorderPoint = ReorderPoint - 1 " &
7776
"WHERE ReorderPoint Is Not Null"
7877

7978
command = New SqlCommand(commandText, connection)
@@ -139,7 +138,7 @@ Public Class Form1
139138

140139
' You can create the delegate instance as you
141140
' invoke it, like this:
142-
Me.Invoke(New DisplayInfoDelegate(AddressOf DisplayStatus), _
141+
Me.Invoke(New DisplayInfoDelegate(AddressOf DisplayStatus),
143142
String.Format("Ready(last error: {0}", ex.Message))
144143
Finally
145144
isExecuting = False
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net9.0-windows</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
Option Explicit On
22
Option Strict On
3-
4-
Imports System.Data
53
' <Snippet1>
64
Imports System.Data.SqlClient
75

@@ -12,11 +10,11 @@ Module Module1
1210
' BeginExecuteNonQuery functionality.
1311
' The WAITFOR statement simply adds enough time to prove the
1412
' asynchronous nature of the command.
15-
Dim commandText As String = _
16-
"UPDATE Production.Product SET ReorderPoint = ReorderPoint + 1 " & _
17-
"WHERE ReorderPoint Is Not Null;" & _
18-
"WAITFOR DELAY '0:0:3';" & _
19-
"UPDATE Production.Product SET ReorderPoint = ReorderPoint - 1 " & _
13+
Dim commandText As String =
14+
"UPDATE Production.Product SET ReorderPoint = ReorderPoint + 1 " &
15+
"WHERE ReorderPoint Is Not Null;" &
16+
"WAITFOR DELAY '0:0:3';" &
17+
"UPDATE Production.Product SET ReorderPoint = ReorderPoint - 1 " &
2018
"WHERE ReorderPoint Is Not Null"
2119

2220
RunCommandAsynchronously(commandText, GetConnectionString())
@@ -25,7 +23,7 @@ Module Module1
2523
Console.ReadLine()
2624
End Sub
2725

28-
Private Sub RunCommandAsynchronously( _
26+
Private Sub RunCommandAsynchronously(
2927
ByVal commandText As String, ByVal connectionString As String)
3028

3129
' Given command text and connection string, asynchronously execute
@@ -46,7 +44,7 @@ Module Module1
4644
Threading.Thread.Sleep(100)
4745
count += 1
4846
End While
49-
Console.WriteLine("Command complete. Affected {0} rows.", _
47+
Console.WriteLine("Command complete. Affected {0} rows.",
5048
command.EndExecuteNonQuery(result))
5149
Catch ex As SqlException
5250
Console.WriteLine("Error ({0}): {1}", ex.Number, ex.Message)
@@ -67,7 +65,7 @@ Module Module1
6765
' If you have not included "Asynchronous Processing=true" in the
6866
' connection string, the command is not able
6967
' to execute asynchronously.
70-
Return "Data Source=(local);Integrated Security=SSPI;" & _
68+
Return "Data Source=(local);Integrated Security=SSPI;" &
7169
"Initial Catalog=AdventureWorks; Asynchronous Processing=true"
7270
End Function
7371
End Module
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Option Strict On
44
Imports System.Data
55
' <Snippet1>
66
Imports System.Data.SqlClient
7+
Imports System.Windows.Forms
78
Imports System.Xml
89

910
Public Class Form1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net9.0-windows</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
11+
</ItemGroup>
12+
13+
</Project>

0 commit comments

Comments
 (0)