請教大家
下列語法為透過參數抓取所要的資料後還回顯示名稱的應用, 要如何讓他可傳回多筆值給同一個 id, 謝謝
dim constring as string="db connection string"
dim ourDataTable As DataTable = nothing
Dim connection as Npgsql.NpgsqlConnection = New Npgsql.NpgsqlConnection(conString)
connection.open()
dim ourAdapter as Npgsql.NpgsqlDataAdapter = New NpgsqlDataAdapter("select .....",connection)
try
outDatatable = new datatable
ourAdapter.Fill(ourDataTable)
for i As integer = 0 to ourDataTable.Rows.Count -1
if IsDBNull(id) then
Return ""
Else
If ourDataTables.Rows.Count <> 0 then
Return ourDataTable.Rows(i)("user_name").ToString & "_"
Else
Return ""
End If
End if
Next
sub沒有回傳值,function也只能回傳一個值,但你可以用ByRef 把要傳過去sub的參數以傳址的方式處理,sub內再直接變更參數內容就可以達到你要的多回傳值的目的
'主程式
A="what"
B=""
MySub(A,B)
.......
Sub MySub(ByRef A As String,ByRef B As String)
B="XXXXXXXXXXX'
A="YYYYYYYYYYYY"
End Sub
或是用function as object的方式回傳物件,物件可自定內容,就不會只有一個型態的回傳值可用了