2011-04-27 68 views
0

我正在使用Oracle命令dbms_output.get_line從存儲過程中檢索輸出。一旦我的代碼運行命令,我通過32000字節長的緩衝區字符串檢索結果。替換.NET字符串中的Oracle換行符

不可避免地,此字符串將有甲骨文換行符(CHR(10)和CHR(13))在它,我想與Environment.NewLine取代因此可以顯示在一個標準輸出Winforms文本框。

這裏是我一直使用的代碼 - 我不記得現在我在哪裏得到了Oracle命令,但是如果我找到它,我會添加鏈接。

Dim cmdGetOutput As New OracleCommand("declare " & _ 
" l_line varchar2(255); " & _ 
" l_done number; " & _ 
" l_buffer long; " & _ 
"begin " & _ 
" loop " & _ 
" exit when length(l_buffer)+255 > :maxbytes OR l_done =1; " & _ 
" dbms_output.get_line(l_line, l_done); " & _ 
" l_buffer := l_buffer || l_line || chr(10); " & _ 
" end loop; " & _ 
" :done := l_done; " & _ 
" :buffer := l_buffer; " & _ 
"end;", cnOracle) 

cmdGetOutput.Parameters.Add("maxbytes", OracleType.Int16) 
cmdGetOutput.Parameters("maxbytes").Value = 32000 
cmdGetOutput.Parameters.Add("done", OracleType.Int16) 
cmdGetOutput.Parameters("done").Direction = ParameterDirection.Output 
cmdGetOutput.Parameters.Add("buffer", OracleType.LongVarChar, 32000) 
cmdGetOutput.Parameters("buffer").Direction = ParameterDirection.Output 

Dim strOutput As List(Of String) = New List(Of String) 
Dim intStatus As Integer = 0 
Try 
    While True 
     cmdGetOutput.ExecuteNonQuery() 
     strOutput.Add(cmdGetOutput.Parameters("buffer").Value) 
     If cmdGetOutput.Parameters("done").Value = 1 Then 
     Exit While 
     End If 
    End While 
Catch ex As Exception 
    MsgBox(ex.Message) 
Finally 
    For ixLines as Integer = 0 to strOutput.Count - 1 
     txtOutput.Text = txtOutput.Text & strOutput(ixLines) 
    Next 
End Try 

當我運行這個時,txtOutput將在換行符應該是的地方有框字符。

感謝大家的幫助!

回答

0

首先,該代碼甚至不應該編譯。您不能將List(的字符串)分配給TextBox.Text屬性。

秒,String類定義了一個Replace(searchstring,replacementstring)方法。

+0

我以爲Oracle中的Chr(10)和Chr(13)與.NET不同,但我錯了。 – Riddari 2011-04-28 15:55:55