Have you tried with if(dr.Read())?
protected void Page_Load(object sender, EventArgs e)
{
string str = Request.QueryString["uname"];
SqlConnection conn = new SqlConnection();
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["leave"].ConnectionString;
conn.Open();
SqlCommand cmd = new SqlCommand("select name,code from emp_details where uname='" + str + "'", conn);
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
name.Text = dr["name"].ToString();
code.Text = dr["code"].ToString();
}
}
There is possibility that you won't have any value against that string in DB.
Check by placing breakpoint on if.
Also don't forget to close dr after you finish your operation by writing:
if(dr!=null)
dr.Close();