HELP with: Webservice for autocompleteextender in access (mdb)

Last post 11-07-2006 2:08 AM by yyy8347. 1 replies.

Sort Posts:

  • HELP with: Webservice for autocompleteextender in access (mdb)

    11-03-2006, 4:48 PM
    • Loading...
    • vgarcias
    • Joined on 07-19-2006, 7:56 AM
    • Veracruz, Mexico
    • Posts 2

    I'm trying to build a webservice that will be consumed by an aspx with the ajax control autocompleteextender, but the webservice produces the following error:

    System.InvalidCastException: No se puede convertir un objeto de tipo 'System.Object[]' al tipo 'System.String[]'.
    en WebService.GetWordList(String prefixText, Int32 count) en C:\Inetpub\Webs\MedSid\App_Code\WebService.vb:

     What am I doing wrong?

     

    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System
    Imports System.IO
    Imports System.Collections
    Imports System.Collections.Generic
    Imports System.Threading
    Imports System.Xml.Serialization
    Imports System.Data
    Imports System.Data.SqlClient
    _
    _
    _
    Public Class WebService
    Inherits System.Web.Services.WebService
    _
    Public Function GetWordList(ByVal prefixText As String, _
    ByVal count As Integer) As String()
    If autoCompleteWordList Is Nothing Then
    Dim MyArrayList As ArrayList = New ArrayList
    Dim connectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("medsidConnectionString").ConnectionString.ToString
    Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
    Dim queryString As String = "SELECT Distinct([Pacientes].Nombre) FROM [Pacientes] WHERE '" & prefixText & "%' ORDER BY Nombre"
    Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection
    dbConnection.Open()
    Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    While dataReader.Read()
    MyArrayList.Add(dataReader("Nombre"))
    End While
    Dim temp As String()
    temp = MyArrayList.ToArray()
    Array.Sort(temp, New CaseInsensitiveComparer())
    autoCompleteWordList = temp
    End If
    Dim index As Integer = Array.BinarySearch(autoCompleteWordList, _
    prefixText, New CaseInsensitiveComparer())
    If index < 0 Then
    index = Not index
    End If
    Dim matchingCount As Integer
    For matchingCount = 0 To count - 1
    If Not (matchingCount + index) < autoCompleteWordList.Length Then
    Exit For
    End If
    If Not autoCompleteWordList((index _
    + matchingCount)).StartsWith(prefixText, _
    StringComparison.CurrentCultureIgnoreCase) Then
    Exit For
    End If
    Next matchingCount
    Dim returnValue(matchingCount - 1) As String
    If matchingCount > 0 Then
    Array.Copy(autoCompleteWordList, index, returnValue, 0, _
    matchingCount)
    End If
    Return returnValue
    End Function
    End Class
  • Re: HELP with: Webservice for autocompleteextender in access (mdb)

    11-07-2006, 2:08 AM
    Answer
    • Loading...
    • yyy8347
    • Joined on 09-19-2006, 7:00 AM
    • Posts 703

    Hi

    You assign IDataReader type to string type which results in the error.

    try this:

    Dim temp As IDataReader () = CType(MyArrayList.ToArray(GetType(IDataReader )), IDataReader ())
     Hope it helps.
    Sincerely,
    Young Fang
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter