Displaying SQL Server data in Windows Forms

Asked

Viewed 48 times

-1

I am wanting to display the information of certain person I am looking for in the SQL Server Database on a label in Windows Forms, but when I run the code it displays System.Data.SqlClient.SqlDataReader.

Could someone help me?

private void button2_Click(object sender, EventArgs e)
{
    string resultado = label3.Text;
    string conexao = @"Data Source=DESKTOP-4FN042S\SQLEXPRESS;Initial Catalog=TESTE;Integrated Security=True";
    SqlConnection con = new SqlConnection(conexao);

    try
    {
        con.Open();

        SqlCommand comando = new SqlCommand("SELECT * FROM Cliente WHERE Nome_Cli LIKE '%@nome'", con);

        //Inserindo dados da text box pra procurar no SQL
        comando.Parameters.Add(new SqlParameter("nome", this.textBox2.Text));

        SqlDataReader leitor = comando.ExecuteReader();

        label3.Text = leitor.ToString();

    }
    catch (SqlException ex)
    {
        MessageBox.Show("Erro ao conectar no banco" + ex);
    }
    finally
    {
        con.Close();
    }
}

1 answer

-1

your question is half vague, would you have a datagrid to see these names or a list? or would you just type in some bank name? or you want a search system? explain better there so that we can help you, a hug.

  • Do not use the answer as a way to ask questions or give suggestions, to do this you can use the comments. ;)

Browser other questions tagged

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