The problems seem like
Session["subid"].ToString()
is null in your code. So when you pass it, it throws this error telling you that this variable is a null and the SqlCommand cannot be generated on a null.
You can fix this issue yourself, null, actually is a very basic kind of error that new developers have to face. It means that the variable actually doesn't exist in the context (memory to be precise).
There are many posts that you can read and the answer is same, You need to initialize the variable's value to be anything, but not a null value.
This might do,
if(Session["subid"] != null) {
SqlCommand cmd = new SqlCommand("select top 1 queid from Exam_Details where subid='" + Session["subid"].ToString() + "'", cnn);
} else {
}
Read
this[
^] technical blog post of mine. You might be able to understand, what this error is, how to solve it and how to stop it from occuring again.
Good luck!