Hello,
Here is some issue in your codes,
command text will like this
cmd.CommandText = "select * from Teble_name where columnname = '" + str +"'";
No need this line because ExecuteNonQuery is use for INSERT/UPDATE/DELETE Operation no need for Select operation
cmd.ExecuteNonQuery();
here is a complete code for select data may this help you
string ConnectionString = ConfigurationManager.ConnectionStrings["ConStrName"].ConnectionString;
DataTable dt = new DataTable();
string sql = "SELECT * FROM TABLE_NAME WHERE COLUMNNAME = '" + value + "';
//Take the connection
SqlConnection connection = new SqlConnection(ConnectionString);
try
{
//now open the connection
connection.Open();
//Take a command with query and connection
SqlCommand command = new SqlCommand(sql, connection);
//say the command type
command.CommandType = CommandType.Text;
//take a dataadapter for selecting data
SqlDataAdapter DataAd = new SqlDataAdapter(command);
//fill the datatab
DataAd.Fill(dt);
//close the connection
connection.Close();
GridView1.DataSource = dt;
GridView1.DataBind();
//return the table
return dt;
}
catch (Exception ex)
{
connection.Close();
throw new Exception(ex.Message.ToString());
//or you can throw exception
}