我正在编写一个Windows服务,它将从一个表中读取记录并将它们写入另一个表。问题是当我声明cmd = New SqlCommand(l_sSQL)代码停止执行时 但该服务仍将运行。我可以使用该服务插入另一个表,但我无法从另一个表中读取。
代码示例:
Private Sub dbcon()
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim x As String
Try
con.ConnectionString = "Data Source=xxxx;Initial Catalog=xxxxx;Persist Security Info=True;User ID=sa;Password=xxxxxxx"
con.Open()
cmd.Connection = con
cmd = New SqlCommand()
Dim i As Integer
l_sSQL = "SELECT * ozekimessageout"
cmd = New SqlCommand(l_sSQL)\\stops executing here
adapter.SelectCommand = cmd
adapter.Fill(ds)
For i = 0 To ds.Tables(0).Rows.Count - 1
x = (ds.Tables(0).Rows(i).Item(1))
下
End Sub
请帮助......
答案 0 :(得分:1)
您不需要:SELECT * FROM ozekimessageout
另外:你正在'新建'cmd两次,没有必要。