-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();
}
}
Do not use the answer as a way to ask questions or give suggestions, to do this you can use the comments. ;)
– Pedro Paulo