2011-07-20 34 views
0

我在寫一個windows服務,它將從一個表讀取記錄並將它們寫入另一個表。問題是當我聲明cmd =新的SqlCommand(l_sql)代碼停止執行 但該服務仍將運行。我可以使用服務插入到其他表中,但我不能從其他表中讀取。Windows服務從一個表中讀取並插入另一個表

代碼示例:

私人小組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)) 

下一個

末次

請幫助....

回答

1

難道你需要: SELECT * FROM ozekimessageout

加:你是'新'cmd兩次,沒有必要。

+0

謝謝你,我已經做了這些改變,但問題仍然保持不變,服務運行,但一旦我引入 – Aly

+0

謝謝你,我已經做了這些改變,但問題仍然保持不變,服務運行,但一旦我介紹sqladapter聲明它停止 – Aly

+0

謝謝你,我已經做出了這些更改,但問題仍然保持不變,服務運行,但一旦我介紹sqladapter聲明它停止Dim myReader As SqlDataReader = cmd.ExecuteReader()是不是Windows服務接受SQL適配器? – Aly

相關問題