}
catch (Exception ex)
{
}
That's wrong: you swallow any exception, hence you have no chance to get rid of the error.
Also, you do not close the connection in case of an exception. I suggest a using directive:
using(SqlConnection con = new SqlConnection())
{
con.ConnectionString = ... etc.
}
And
if (gridrecord.Rows.Count == 0)
{
lblmsg.Visible = true;
lblmsg.Text = " No data found";
}
will never reset that label when a query succeeds after a previous failure.