本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Data.SqlClient,代码行数:67,代码来源:SqlCommand.Cancel
注:本文中的System.Data.SqlClient.SqlCommand.Cancel方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论