Executenonquery è per UPDATE, DELETE, INSERT.
codice:
using (SqlConnection connection = new SqlConnection("tuaConnString"))
{
// crea l'oggetto command
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "TUA QUERY SELECT";
// Apre la connessione e riempie il datareader
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
tuaGridView.DataSource = reader;
tuaGridView.DataBind();
}
}
catch(Exception ex)
{
Console.Writeline(ex.message);
}
}
PS: tieni ben presente che la tecnica descritta è SCONSIGLIATA. E' meglio non scrivere codice SQL nelle stringhe, ma nelle Stored Procedure