First of all about the error:
SqlDataAdapter ad = new SqlDataAdapter(qry, ConfigurationManager.ConnectionStrings["key"].ConnectionString);
DataSet dsp = new DataSet();
ad.Fill(dsp);
This is a WRONG way to use SQLDataAdapter. You have not mentioned the SqlCommand that will be associated adapter to get data. Without that, Fill would not work.
Try something like:
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(queryString, connection);
adapter.Fill(dataset);
Look here:
SqlDataAdapter Class[
^]
After resolving this error, would just like to point out that there are few places you need to improve your coding. Like:
1.) Instead of... Int32 i; => int i;
2.) Instead of... string d =""; => string d = string.Empty;
3.) Keep a friendly names of variables and controls like, i as itemCount
4.) Keep checks for null at necessary places like accessing connection string. You directly passed that into query. You should first check if it is available or not (not null when retrieved from DB), then create a SqlConnection using it and use the connection object in adapter.