List(Of String)计算数据库列值

时间:2012-02-10 06:07:13

标签: vb.net string web-services sql-server-2008

我在DB中有一些数据,我在List(Of String)中使用WebService并使用以下代码返回该List

    Public Function getDetails() As List(Of String)
        Dim Connection As SqlConnection = Nothing
        Dim Command As SqlCommand = Nothing
        Dim DataReader As SqlDataReader = Nothing

        Try
            Dim MyList As New List(Of String)

            Connection = New SqlConnection("Connection String")
            Connection.Open()
            Command = New SqlCommand("select * from TBL", Connection)
            DataReader = Command.ExecuteReader()

            While (DataReader.Read)
                MyList.Add(DataReader("Col1"))
                MyList.Add(DataReader("Col2"))
                MyList.Add(DataReader("Col3"))
                MyList.Add(DataReader("Col4"))

            End While

            If MyList.Count <> 0 Then
                Return MyList
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        Finally
            DataReader.Close()
            Connection.Close()
        End Try
End Function

现在我有一个VB.net程序,我使用Web服务并使用下面的代码获取值

Dim webQuery As QueryWebService.Service = New QueryWebService.Service


    Dim queryDetails As String()
    Dim i As Integer = 0

    queryDetails = webQuery.getStudentQuery()

    While i < queryDetails.Length
        txtQuery.Text = txtQuery.Text + " " + queryDetails.GetValue(i)
        i = i + 1
    End While

值很好,但是它们在一个String()中,我想在不同的TextField(Multiline)中显示每列的值,我该怎么做?

谢谢。

1 个答案:

答案 0 :(得分:0)

您的方法返回一个列表,但您的queryDetails是一个数组。尝试将queryDetails作为一个列表。