How to fill a textbox with a Mysql LIKE?

Asked

Viewed 781 times

1

I am trying to fill in the textbox, when the client is typing the initials of his Name, select goes to the bank and tries to get the information. However, I have no idea how to send

I’ll show you my View 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;
     }
  }

}

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) to use jQuery UI and create your own AJAX requests.

By way of the AJAX Control Toolkit (which I find the most interesting because your project is in Web Forms), the implementation would be using a component called AutoCompleteExtender and programming 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 on which you have doubt, which I will answer.

  • 1

    Thanks, Gypsy. Again, you help me. I’ll take a look at Ajax Control.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.