本文整理汇总了VB.NET中System.Data.SqlClient.SqlCommand.Cancel方法的典型用法代码示例。如果您正苦于以下问题:VB.NET SqlCommand.Cancel方法的具体用法?VB.NET SqlCommand.Cancel怎么用?VB.NET SqlCommand.Cancel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.Cancel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Module1
' 导入命名空间
Imports System.Data
Imports System.Data.SqlClient
Imports System.Threading
Module Module1
Private m_rCommand As SqlCommand
Public Property Command() As SqlCommand
Get
Return m_rCommand
End Get
Set(ByVal value As SqlCommand)
m_rCommand = value
End Set
End Property
Public Sub Thread_Cancel()
Command.Cancel()
End Sub
Sub Main()
Dim connectionString As String = GetConnectionString()
Try
Using connection As New SqlConnection(connectionString)
connection.Open()
Command = connection.CreateCommand()
Command.CommandText = "DROP TABLE TestCancel"
Try
Command.ExecuteNonQuery()
Catch
End Try
Command.CommandText = "CREATE TABLE TestCancel(co1 int, co2 char(10))"
Command.ExecuteNonQuery()
Command.CommandText = "INSERT INTO TestCancel VALUES (1, '1')"
Command.ExecuteNonQuery()
Command.CommandText = "SELECT * FROM TestCancel"
Dim reader As SqlDataReader = Command.ExecuteReader()
Dim rThread2 As New Thread( _
New ThreadStart(AddressOf Thread_Cancel))
rThread2.Start()
rThread2.Join()
reader.Read()
Console.WriteLine(reader.FieldCount)
reader.Close()
End Using
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
Private Function GetConnectionString() As String
' To avoid storing the connection string in your code,
' you can retrieve it from a configuration file.
Return "Data Source=(local);Initial Catalog=AdventureWorks;" _
& "Integrated Security=SSPI;"
End Function
End Module