Jump to content

Problema com Script


LN10

Recommended Posts

Bom dia.

Tenho este código em que deveria fazer uma pesquisa na Tabela "Programas", só que parece que o código não corre.

Não dá erro nenhum, simplesmente não faz a sua função.

	<title></title>
	<script src="js/jquery-latest.js" type="text/javascript"></script>
	<link rel="stylesheet" href="css/jquery.autocomplete.css" type="text/css" />
	<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
	<script type="text/javascript">
			$(document).ready(function () {
					$("#txtCodProg").autocomplete("Cod_Prog.ashx");
			});
	</script>

ashx
<%@ WebHandler Language="C#" Class="Cod_Prog" %>

using System;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Configuration;

public class Cod_Prog : IHttpHandler
{

	public void ProcessRequest(HttpContext context)
	{
			string pesq_cod = context.Request.QueryString["q"];
			string sql = "Select * from Programas where Codigo Like '%" + pesq_cod + "%'";

			using (SqlConnection connection = new SqlConnection("Data Source=LN\\Digisoft;Initial Catalog=Registos;Integrated Security=True"))
			using (SqlCommand command = new SqlCommand(sql, connection))
			{
					connection.Open();

					using (SqlDataReader reader = command.ExecuteReader())
					{
							while (reader.Read())
							{
									context.Response.Write(reader.GetInt32(0) + Environment.NewLine);
							}
					}
			}
	}

	public bool IsReusable
	{
			get
			{
					return false;
			}
	}
}
Edited by Caça
GeSHi
Link to comment
Share on other sites

Estás a escrever os dados na resposta um por linha com uma mudança de linha do sistema operativo (\r\n no caso do windows).

Tipo:

Resultado1

Resultado2

Resultado3

Não me lembro ao certo o que o plugin precisa, mas penso que não é isso, mas sim um array em json ou xml.

Matraquilhos para Android.

Gratuito na Play Store.

https://play.google.com/store/apps/details?id=pt.bca.matraquilhos

Link to comment
Share on other sites

isto:

context.Response.Write(reader.GetInt32(0) + Environment.NewLine);

Não vale nada. Para além de o plugin autocomplete provavelmente não funcionar, não passas muito provavelmente os valores que precisas. Diria que queres passar um id e um campo de texto para usar no autocomplete e com este código passas na melhor das hipóteses o id apenas

Precisas escrever json ou xml para a resposta como o bruno1234 já disse.

Já te respondi a esta mesma questão em outros tópicos e já te enviei mensagem com um exemplo de código para resolveres o problema.

Melhor melhor só se me pagares para te fazer isso lol

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.