Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

AutoCompleteExtender question

$
0
0

I have a text box with an AutoCompleteExtender attached. I am trying to use data returned from a stored procedure as the data source for a web service that worked with the extender when I used a select statement instead of the SPROC. Initially the select simply looked for users names and the extender worked properly. However,  I want to  be able to type in a   name, city, or statename and have the extender display results for all three. Example:

PROCEDURE [dbo].[multisearch] 

	@item varchar(50)
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	AS
	BEGIN

	SET NOCOUNT ON;

	declare @srchitem table(
	item varchar(50)
)

Insert into @srchitem 
select fname +' ' + lname

from riders

Insert into @srchitem
select distinct  city
from address


Insert into @srchitem
select distinct  statename
from state

 Select * from @srchitem where item like @item +'%'
END


The stored procedure is fairly simple. If I execute the procedure in the SQL Management studio like

EXEC multisearch 'ken' I get a bunch of Kens and Kenneths and the state Kentucky so I think that the SQL is OKAY.

but when I try to execute from the app  (debugging) it stops before it finishes the code:

[WebMethod]
public List<string> GetItems(string prefixText)
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BDUCConnectionstring"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "[multisearch]";
//SqlCommand cmd = new SqlCommand("select riderid, dname from riders where dname like @name+'%'", con);
cmd.Parameters.AddWithValue("@item", prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
int cnt = dt.Rows.Count;
List<string> items = new List<string>();

    for (int i = 0; i < dt.Rows.Count; i++)
{
    items.Add(dt.Rows[i][0].ToString());
    items.Add(dt.Rows[i][1].ToString());
 //Names.Add(dt.Rows[i][0].ToString());
  string sid = dt.Rows[i][0].ToString();

    
}
    return items;
} }
When the code hits the ine 'da.Fill(dt);'
it stops running and the last part of the code never runs.There are no errors it just quits. Here is the ASPX:
<asp:TextBox ID="tbSearch" runat="server" OnTextChanged="tbSearch_TextChanged" /><ajaxToolkit:AutoCompleteExtender ID="txtfind_AutoCompleteExtender" runat="server" MinimumPrefixLength="2" EnableCaching="true" 
                    CompletionSetCount="1" CompletionInterval="1000"  ServicePath="~/Mutts/WebService.asmx" 
                    Enabled="True" ServiceMethod="GetItems" TargetControlID="tbSearch"></ajaxToolkit:AutoCompleteExtender>
Anyone know what the problem is?


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>