How to fill a textbox with a MySQL LIKE?

1

I'm trying to fill in the textbox, when the client is typing the initials of their name, the select goes into the bank and tries to fetch the information. However, I have no idea how to command

I'll show you how my View is and my DAL.

View:

 

<div class="control-group">
    <label>Nome</label><asp:TextBox  ID="txbAlgNome" runat="server"></asp:TextBox><br />

</div>
<div>
        <asp:Button ID="button_cad_1"  runat="server" Text="Salvar" onclick="button1_cad_veiculo" />
</div>

View code:

using System;
using System.Collections.Generic;
using System.Linq; 
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Geax1.Model;
using Geax1.DAL;

namespace Geax1.Views
{
  public partial class AluguelVeiculos : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
        //enviando o nome para o SELECT no meu DAL
        _AluguelVeiculos aldata = new _AluguelVeiculos();

        aldata.Nomecliente1 = txbAlgNome.Text;

        _ListaNome.ListaNomeCliente(aldata);


        //preenchendo os campos do TextBox, após o select Like
        txbAlgNome.DataBinding = _ListaNome.retornaNomecliente();

      }
    }
  }

My DAL:

namespace Geax1.DAL
{
  public class _ListaNome
  {
    private static List<_AluguelVeiculos> lc = new List<_AluguelVeiculos>();

    public static void ListaNomeCliente(_AluguelVeiculos obj)
    {
        using (var conn = new MySqlConnection("server=127.0.0.1;Database=xpto;User ID=root;Password='';"))
        {

            MySqlDataAdapter adapter = new MySqlDataAdapter();
            adapter.SelectCommand = new MySqlCommand("SELECT nome, cpf FROM tab_cliente WHERE nome LIKE '%nome% ;", conn);

            DataSet dataset = new DataSet();
            adapter.Fill(dataset);

            foreach (DataRow linha in dataset.Tables[0].Rows)
            {
                _AluguelVeiculos cl_1 = new _AluguelVeiculos();

                cl_1.Nomecliente1 = Convert.ToString(linha["nome"]);
                cl_1.CpfCliente1 = Convert.ToString(linha["cpf"]);

                lc.Add(cl_1);
            }
        }
    }

    public static List<_AluguelVeiculos> retornaNomecliente() 
    {
        _AluguelVeiculos al = new _AluguelVeiculos();
        ListaNomeCliente(al);
        return lc;
     }
  }

}

    
asked by anonymous 25.09.2014 / 18:44

1 answer

1

The way suggested by Microsoft advises you to install the ASP.NET Ajax Control Toolkit , although it is possible (with greater difficulty) use the jQuery UI and create your own AJAX requests.

By the way of the AJAX Control Toolkit (which I find most interesting because your project is in Web Forms), the implementation would be using a component called AutoCompleteExtender and scheduling a WebMethod to make a call on your DAL . As the script is very large, it is not worth putting in an answer, but you can edit your question and put the points where you have questions, which I will answer.

    
25.09.2014 / 20:21