调用函数返回字符串矩阵时的VBNet预期表达式

时间:2013-05-28 11:38:15

标签: asp.net vb.net

我有一个函数(应该)从DB

中的随机记录返回一个二维字符串数组/矩阵
Function GetRndRecords(table As String, fields As String(), num_records As Integer) As String(,)
    If not connected Then
        Connect()
    End If
    Dim Rand as New Random()
    Dim strSQL As String
    Dim ID_Max As Integer
    Dim Results(num_records,fields.Length) As String
    strSQL = "SELECT COUNT(*) FROM " & table
    dbcomm = New OleDbCommand(strSQL,dbconn)
    ID_Max = dbcomm.ExecuteScalar()
    Dim i As Integer
    For i=0 To num_records-1
        Do
            Dim Rand_ID As Integer = Rand.Next(1,ID_Max)
            Dim j As Integer
            strSQL = "SELECT "                                      ' strSQL begin
            For j = 0 To fields.Length-1
                If(j <> 0) Then
                    strSQL &= ", "
                End If
                strSQL &= fields(j)
            Next
            strSQL &= " FROM " & table & " WHERE ID = " & Rand_ID   ' strSQL end
            dbcomm = New OleDbCommand(strSQL,dbconn)
            dbread = dbcomm.ExecuteReader()
            dbread.Read()
            For j = 0 To fields.Length-1
                Results(i,j) = dbread.GetString(j)
            Next
        Loop Until dbread.GetString(0) <> ""
    Next
    Return Results
End Function

我在这个函数中没有任何问题,但是当我调用它时(在Page_Load事件中)我得到一个(“BC30201:表达式预期。”)

Sub Page_Load
    Dim Rand_Records As String(,)
    Rand_Records = GetRndRecords("Autore",{"ID","Nome"},PossibleAnswers-1)
End Sub

我甚至试过这个,结果相同

Sub Page_Load
    Dim Rand_Records As String(,)
    Rand_Records = new String({"ID1","Nome1"},{"ID2","Nome2"},{"ID3","Nome3"})
End Sub

任何人都可以解释我为什么吗?

0 个答案:

没有答案