How to create a 'next record' button of a BD in C#

Asked

Viewed 74 times

0

Hello, I’m trying to make a Windowsform with a button 'next' to display data in some Textbox see image:

inserir a descrição da imagem aqui

This button is just an alternative, it should go through all the BD records from the first IF the textbox is not completed, if it is already completed, it must go through all records containing the NAME similar to the typed.

I tried to use the option Reader.NextResult() but without success.

How should I proceed?

Follow code from Search button (magnifying glass):

private void button1_Click(object sender, EventArgs e)
    {
        //Declara sintrg de conexão com BD
        OleDbConnection Connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\xxxxx.accdb");

        //Abrir conexão com BD
        Connection.Open();

        //Declarar Comando SQL
        OleDbCommand Command = Connection.CreateCommand();
        Command.CommandText = "SELECT * FROM tb_YYYY WHERE Nome LIKE '%" + txtUserOUNome.Text + "%'";

        //Declarar DataReader
        OleDbDataReader Reader = Command.ExecuteReader();

        while (Reader.Read())
        {
            txtPesqNome.Text = Convert.ToString(Reader["Nome"]);
            txtPesqUsuario.Text = Convert.ToString(Reader["Usuario"]);
            txtPesqMail.Text = Convert.ToString(Reader["Mail"]);
        }

        //Fechar Reader e Conexão
        Reader.Close();
        Connection.Close();
    }
  • And if you store the results in a list and when you click on "next", search for the next index?

  • is an option, but I don’t know how to do it, I would have an example? :(

No answers

Browser other questions tagged

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