2013-05-28 29 views
0

我背後有VB.net這樣的代碼:工藝處理重定向到URL

Protected Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button.Click 
     Dim Adapter As New SqlDataAdapter 
     Dim sql As String = "select House , OPR_BALANCE from vAgeLast where LEN(HOUSE) = 8 and OPR_BALANCE > 1000000 order by OPR_BALANCE desc" 
     SqlConn.Open() 
     sqlCmd = New SqlCommand(sql, SqlConn) 
     Adapter.SelectCommand = sqlCmd 
     Adapter.Fill(ds) 
     For i = 0 To ds.Tables(0).Rows.Count - 1 
      idCustomer = ds.Tables(0).Rows(i)("House").ToString() 
      amt = ds.Tables(0).Rows(i)("OPR_BALANCE").ToString() 
      lang = "0" 
      aid = "000000" 
      Dim result As String = "http://soap.Services.com:2121/WS.aspx/?c=1&id=" + idCustomer + "&lang=" + lang + "" 
      Response.Redirect(result) 

     Next 
     Adapter.Dispose() 
     sqlCmd.Dispose() 
     SqlConn.Close() 
    End Sub 

在此代碼,我想處理來自數據集的結果所有的價值,這隻能得到通過重定向到URL,但是當我運行代碼,它只運行一次。

是否可以重定向到網址,而無需在網站上獲得反饋顯示?

+1

如果拋出異常,則永遠無法在sql連接上調用.Close()。如果這種情況經常發生,可以將自己鎖定在數據庫之外。你需要一個Try/Finally或Using塊。 –

+0

當我得到這一行時如何:Dim result As String ='「http://soap.Services.com:2121/WS.aspx/?c=1&id=」+ idCustomer +「&lang =」+ lang +「」 Response.Redirect(result)'是否有可能response.redirect不止一次執行? – Sabilv

+0

Response.Redirect()**停止**當前頁面並將您發送到新頁面。如果你有20條記錄,你希望這個結果是什麼?在用戶瀏覽器中打開20個選項卡? –

回答

0

我從其他用戶得到它。

在循環內重定向不會工作。您需要以其他方式致電該服務。 嘗試使用DownloadString方法WebClient。通過以下方式提取result

Dim client As New WebClient() 
Dim result As String = client.DownloadString("http://soap.Services.com:2121/WS.aspx/?c=1&id=" + idCustomer + "&lang=" + lang) 
0

嘗試增加「點心SqlConn作爲新的SQLConnection」

+0

當我得到這一行時如何:Dim result As String ='「http://soap.Services.com:2121/WS.aspx/?c=1&id=」+ idCustomer +「&lang =」+ lang +「」 Response.Redirect(result)'是否有可能response.redirect不止一次執行? – Sabilv