I have got the autocomplete textbox working but having problems using 2 where conditions
Imports Microsoft.VisualBasic Imports System
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Configuration _
_
_
_
Public Class AutoComplete2 Inherits System.Web.Services.WebService _
_ Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim cn As New SqlConnection(ConfigurationManager.ConnectionStrings("connectionstring").ConnectionString)
Dim cmd As New SqlCommand("SELECT DISTINCT TOP(@nrows) Jobname FROM CustID = @cust AND Job WHERE Jobname like @term", cn)
cmd.Parameters.AddWithValue("nrows", count)
cmd.Parameters.AddWithValue("cust", Session("custid"))
cmd.Parameters.AddWithValue("term", prefixText & "%")
Dim suggestions As New List(Of String)()
cn.Open() Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read()
suggestions.Add(dr(0).ToString())
End While End
Using Return suggestions.ToArray()
End Function
End Class
TgaLamx
Member
25 Points
61 Posts
AJAX AutoComplete from SQL database using VB multiple where conditions
Feb 12, 2013 06:07 PM|LINK
http://forums.asp.net/p/1334397/5298470.aspx#5298470
A carry on from this post as i can't reply it it,
I have got the autocomplete textbox working but having problems using 2 where conditions
Imports Microsoft.VisualBasic Imports System Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Data Imports System.Data.SqlClient Imports System.Collections.Generic Imports System.Web.Script.Services Imports System.Configuration _ _ _ _ Public Class AutoComplete2 Inherits System.Web.Services.WebService _ _ Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String() Dim cn As New SqlConnection(ConfigurationManager.ConnectionStrings("connectionstring").ConnectionString) Dim cmd As New SqlCommand("SELECT DISTINCT TOP(@nrows) Jobname FROM CustID = @cust AND Job WHERE Jobname like @term", cn) cmd.Parameters.AddWithValue("nrows", count) cmd.Parameters.AddWithValue("cust", Session("custid")) cmd.Parameters.AddWithValue("term", prefixText & "%") Dim suggestions As New List(Of String)() cn.Open() Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) While dr.Read() suggestions.Add(dr(0).ToString()) End While End Using Return suggestions.ToArray() End Function End ClassTgaLamx
Member
25 Points
61 Posts
Re: AJAX AutoComplete from SQL database using VB multiple where conditions
Feb 12, 2013 09:48 PM|LINK
I had messed up my sql statement and then used the contextkey to pass the other parameter to the web service
Amy Peng - M...
Star
10127 Points
958 Posts
Microsoft
Re: AJAX AutoComplete from SQL database using VB multiple where conditions
Feb 20, 2013 04:43 AM|LINK
Hi,
I am glad that you have solved your problem by yourself, if you have any other problem, welcome to post it in the asp.net forums.
Best Regards,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store