dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: I am not being able to make a autocomplete textbox

  1. #1
    Join Date
    Sep 2008
    Posts
    5

    I am not being able to make a autocomplete textbox

    Hello All,

    My code in webservice.vb is as follows:
    Code:
    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.data
    Imports System.Data.SqlClient
    Imports System.web.Script.Services
    Imports System.Collections
    Imports System.Collections.Generic
    
    <WebService(Namespace:="http://tempuri.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class WebService
         Inherits System.Web.Services.WebService
    
        <WebMethod()> _
        Public Function GetIDInfo(ByVal prefixText As String)
    
            Dim MyConnection As SqlConnection
            MyConnection = New SqlConnection("server=Server_name;database=database_name;Trusted_Connection=yes; MultipleActiveResultSets=True")
            MyConnection.Open()
    
            Dim cnt, i As Integer
            Dim sql As String
            Dim da As SqlDataAdapter
            Dim cmd As SqlCommand
            Dim dt As DataTable
            Dim items As ArrayList
            Dim dr As SqlDataReader
            sql = "Select studentID from student Where StudentID like '" & prefixText & "' Order By StudentID "
            da = New SqlDataAdapter(sql, MyConnection)
            da.SelectCommand.Parameters.Add("prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%"
            cmd = New SqlCommand(sql, MyConnection)
            dt = New DataTable()
            da.Fill(dt)
            cnt = dt.Rows.Count
            items = New ArrayList(cnt)
            dr = cmd.ExecuteReader
            For i = 0 To cnt
                items(i) = dr.Item("StudentID").ToString()
                i = i + 1
            Next
            Return items
        End Function
    
    End Class
    The code for this in the asp.net page is:
    Code:
    <cc1:AutoCompleteExtender ID="AutoCompleteExtender1"
              runat="server"  ServiceMethod="GetIDInfo" ServicePath="webservice.asmx" TargetControlID="txtStudentID" >
          </cc1:AutoCompleteExtender>
    Could you please indicate the flaw in this code? The code is generating error. I tried debugging step by step and it is not reading any data from the database.

    Thanks a lot in advance.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Welcome to DevX

    What is the error?

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Although I would like to get a resolution for your error, I went snooping around and found this. You might find that interesting to take a look at.

  4. #4
    Join Date
    Sep 2008
    Posts
    5
    When I run the default page. Neither ant error appears not it autocompletes the textbox.
    Running the webservice page gives error of: "Trying to read when there is no data"
    I think that means it is not reading the database.
    Thanks

  5. #5
    Join Date
    Sep 2008
    Posts
    5

    Autocomplete textbox problem

    Hi All,
    I implemented autocomplete textbox in asp .net page as in http://www.eggheadcafe.com/community...h-autocom.aspx

    My webservice.vb code is as follows
    Code:
    Imports System.web.Script.Services
    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.data
    Imports System.Data.SqlClient
    Imports System.Collections
    Imports System.Collections.Generic
    
    <WebService(Namespace:="test")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class WebService
        Inherits System.Web.Services.WebService
    
        <WebMethod()> _
        Public Function GetIDInfo(ByVal prefixText As String)
    
            Dim MyConnection As SqlConnection
            MyConnection = New SqlConnection("server=my_server_name;database=My_db_name;Trusted_Connection=yes; MultipleActiveResultSets=True")
            MyConnection.Open()
    
            Dim cnt, i As Integer
            Dim sql, sql2 As String
            Dim da As SqlDataAdapter
            Dim cmd, cmd2 As SqlCommand
            Dim dt As DataTable
            Dim items As List(Of String)
            Dim dr, dr2 As SqlDataReader
            sql = "Select StudentID from Student Where ID like '" & prefixText & "%' order by StudentID"
            sql2 = "Select count(StudentID) from Student Where ID like '" & prefixText & "%'"
            items = New List(Of String)
            da = New SqlDataAdapter(sql, MyConnection)
            da.SelectCommand.Parameters.Add(prefixText, SqlDbType.VarChar, 50).Value = prefixText & "%"
            cmd2 = New SqlCommand(sql2, MyConnection)
            dr2 = cmd2.ExecuteReader
            If dr2.Read() Then
                cnt = dr2.Item(0)
            End If
            MyConnection.Close()
            MyConnection.Open()
            cmd = New SqlCommand(sql, MyConnection)
            dt = New DataTable()
            da.Fill(dt)
            dr = cmd.ExecuteReader
            If dr.Read() Then
                For i = 0 To cnt
                    items.Add(dr.GetString(0))
    
                    i = i + 1
                Next
            End If
            Return items.ToString()
        End Function
    
    End Class
    When I run the default.aspx file, it is not generating the suggestions for autocomplete.

    What may be the problem?

    Please help me,
    Thanks a lot

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Duplicate Threads Merged

    One question, one thread, one forum section please.

  7. #7
    Join Date
    Sep 2008
    Posts
    5
    Thanks hack!!
    I thought it is slightly different issue, so....

    Somebody please give me the answer....

Similar Threads

  1. Replies: 6
    Last Post: 05-31-2010, 07:19 PM
  2. Replies: 1
    Last Post: 02-28-2007, 07:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center