autocomplete + sql returns null as array item

Last post 10-09-2008 8:40 AM by mbanavige. 1 replies.

Sort Posts:

  • autocomplete + sql returns null as array item

    10-09-2008, 6:47 AM
    • Member
      128 point Member
    • neilhanvey
    • Member since 03-28-2007, 3:05 PM
    • Posts 95

    i've got an autocomplete extender linked to a sql table, the code below is working fine and brings back the correct data, my problem is that it is adding a final array item of null and i know for certain that there are no null values in my table. anyone got any ideas on why it's returning this null value everytime, is there a problem with my array? if anyone is trying to get autocomplete working with sql and needs some example code just give me a shout, thanks in advance for any help

     

     Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()

            Dim sql As String = "Select * from x where y like @prefixText"
            Dim da As SqlDataAdapter = New SqlDataAdapter(sql, Connection)
            da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%"
            Dim dt As DataTable = New DataTable()
            da.Fill(dt)
            Dim items() As String = New String(dt.Rows.Count) {}
            Dim i As Integer = 0
            Dim dr As DataRow
            For Each dr In dt.Rows
                items.SetValue(dr("z").ToString(), i)
                i = i + 1
            Next
            Return items

        End Function

  • Re: autocomplete + sql returns null as array item

    10-09-2008, 8:40 AM
    Answer
    • All-Star
      98,717 point All-Star
    • mbanavige
    • Member since 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 10,410
    • Moderator
      TrustedFriends-MVPs

    arrays are zero based and should be sized according to the highest index you will need which is one less than the count.

    Dim items() As String = New String(dt.Rows.Count-1)

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
Page 1 of 1 (2 items)