Autocomplete Web Service Code
1 Imports System.Web
2 Imports System.Web.Services
3 Imports System.Web.Services.Protocols
4 Imports System.Data.SqlClient
5 Imports System.Data
6
7 ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
8 <System.Web.Script.Services.ScriptService()> _
9 <WebService(Namespace:="http://tempuri.org/")> _
10 <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
11 <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
12 Public Class AutoComplete
13 Inherits System.Web.Services.WebService
14
15 <WebMethod()> _
16 Public Function GetOrderNumber(ByVal prefixText As String, ByVal count As Integer) As String()
17
18 Dim emp As New List(Of String)
19
20 Dim conn As String = "Data Source=GLPT-SQL\CSI_SQL;Initial Catalog=CSITSS;Persist Security Info=True;User ID=*******;Password=*********"
21
22 Dim query As String = "SELECT O.[OrderNumber] FROM [CSITSS].[dbo].[Orders] as O WHERE O.CompanyDiv = 'GLPC-TRANS' and O.Deleted = 0 and O.Terminal = 'COD' and (OrderNumber LIKE '%" & prefixText & "%')"
23
24 Dim da As New SqlDataAdapter(query, conn)
25
26 Dim ds As New DataSet
27 da.Fill(ds)
28
29 If ds.Tables(0).Rows.Count < count Then
30 count = ds.Tables(0).Rows.Count
31 End If
32 Dim items As New List(Of String)
33 For i As Integer = 1 To count
34
35 items.Add(ds.Tables(0).Rows(i - 1).Item(0).ToString)
36
37 Next i
38
39 Return items.ToArray()
40
41 End Function
42 <WebMethod()> _
43 Public Function GetPropertyID(ByVal prefixText As String, ByVal count As Integer) As String()
44
45 Dim emp As New List(Of String)
46
47 Dim conn As String = "Data Source=GLPT-SQL\CSI_SQL;Initial Catalog=CSITSS;Persist Security Info=True;User ID=*******;Password=*********"
48
49 Dim query As String = "SELECT [CustomerID] FROM [CSITSS].[dbo].[Customer] WHERE CustomerID < '9999999999' and CompanyDiv = 'GLPC-TRANS' and (CustomerID LIKE '%" & prefixText & "%')"
50
51 Dim da As New SqlDataAdapter(query, conn)
52
53 Dim ds As New DataSet
54 da.Fill(ds)
55
56 If ds.Tables(0).Rows.Count < count Then
57 count = ds.Tables(0).Rows.Count
58 End If
59 Dim items As New List(Of String)
60 For i As Integer = 1 To count
61
62 items.Add(ds.Tables(0).Rows(i - 1).Item(0).ToString)
63
64 Next i
65
66 Return items.ToArray()
67
68 End Function
69
70 End Class
This web service works but the output below isn't what shows up on the autocomplete menu.
GetOrderNumber Results
1
2 - <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
3 <string>00064979-0</string>
4 </ArrayOfString>
GetPropertyID Results
1
2 - <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
3 <string>0009620000</string>
4 <string>0459620000</string>
5 </ArrayOfString>
GetOrderNumber Results on Textbox
64979
GetPropertyId Results on Textbox
9620000
459620000
How do I make it display the entire string result???